Rob Salgado has done a lot and also cataloged many sites where you might
look for such a program. Here is his link (which is also available in
the "Contributed" section at vpython.org):
http://www.physics.syr.edu/~salgado/software/vpython
Also see the "Lecture Materials" section of
http://www4.ncsu.edu/~rwchabay/mi
I don't however happen to know of an example quite like the one you
imagine. There's a vaguely related program at the second site mentioned
above, 22_Faraday-magnet.py, which illustrates the curly electric field
surrounding a region where there is a time-varying magnetic field due to
a moving magnet. The program 13_E_point_charge.py lets you drag an
electric charge around and see the change in the electric field everywhere.
I'm not sure what you mean by "But it is hard to give up on thinking
about the gravity equations as a set of nested for loops iterating over
arrays of vectors." The stars.py example program works by calculating
the net force on a star due to all the other stars, updating the
momentum of that star after a short time interval dt (final momentum =
initial momentum + net_force*dt), and updating the position of that star
using the final velocity to approximate the average velocity in that
short time interval. What's a bit unusual about stars.py is using
numeric arrays to handle N stars in parallel, where the momentum and
position updates take place on arrays N stars wide. (stars.py also
checks for mergers and carries them out, conserving momentum in the
merger process.)
Bruce Sherwood
Doug Mair wrote:
> I'm new to Python and VPython, I'm impressed with what I've seen so far.
>
> Does anyone know of a Magnet simulation in Python?
>
> I would like to have bar magnets which would attract each other by their
> North / South poles.
>
> It would be cool to have them glued in position or able to move them around
> on a surface. That way you can move one magnet around and see how the
> others react to the one being dragged around.
>
> I've been looking through the stars.py for some hints on making this
> program.
>
> Coming from C#, I really love the fact that the python equations for gravity
> look very much like what I find on WikiPedia. But it is hard to give up on
> thinking about the gravity equations as a set of nested for loops iterating
> over arrays of vectors.
>
>
> Thanks for any help,
> Doug
|