VPython applications for Teaching Physics
Content from the original site
https://web.archive.org/web/2001*/http://physics.syr.edu/~salgado/software/vpython/
is slowly being copied here.
Some links may be broken... but they will be fixed soon.
current academic homepage:
Rob Salgado
up to: visualrelativity.com
last updated 10/31/2015 ( prev update 9/27/2011 )
created Dec 8, 2001 (at Syracuse)
Waves
wave_superposition.py tested with VPython23-2003-10-05
doppler-wavefront.py tested with with Python-2.3.4.exe and VPython-2003-10-15.exe
Kinematics
2D-kinematics-with-vectors.py tested with VPython23-2003-10-04
2D-kinematics-with-vectors-circular.py tested with VPython23-2003-10-04
2D-kinematics-with-vectors-circular-polar.py tested with VPython23-2003-10-04
1D-kinematics.py tested with VPython23-2003-09-04
1D-kinematics-with-vectors.py tested with VPython23-2003-10-04
1D-kinematics-with-vectors-alt.py tested with VPython23-2003-10-04
Electromagnetism
EFieldBuilder-09990.py (v0.9990) tested with VPython-2003-10-05.exe
EFieldBuilder-0997-22.py (v0.9972) requires VPython-2001-12-31.exe
EFieldBuilder-0997.py (v0.997) requires VPython-2001-10-31.exe
EFieldBuilder-0996.py requires VPython-2001-10-31.exe
EFieldBuilder-099.py
Maxwell-Gauss-Coulomb_v275.py tested with Python 2.3/VPython-2003-10-05.exe
Maxwell-Gauss-Magnetic_v275.py tested with Python 2.3/VPython-2003-10-05.exe
Maxwell-Ampere.py (v2.52) tested with VPython-2001-10-31.exe
Maxwell-Ampere_v275.py tested with Python 2.3/VPython-2003-10-05.exe (includes change in color scheme)
Maxwell-Ampere_v276.py tested with Python 2.4/VPython-3.2.9 (includes change in color scheme)
Maxwell-Faraday.py (v2.52) tested with VPython-2001-10-31.exe
Maxwell-Faraday_v275.py tested with Python 2.3/VPython-2003-10-05.exe (includes change in color scheme)
Maxwell-Faraday_v276.py tested with Python 2.4/VPython-3.2.9 (includes change in color scheme)
EMWave-020110.py (v0.5) tested with VPython-2001-10-31.exe
EMWave-030216.py (v0.51) tested with VPython-2001-10-31.exe
EMWave.py (v1.00) tested with VPython-2003-10-05.exe
EMWave-Maxwell.py (v2.51) tested with VPython-2003-10-05.exe
EMWave-Maxwell_v275.py tested with Python 2.3/VPython-2003-10-05.exe (includes change in color scheme)
EMWave-Maxwell_v277.py tested with Python 2.5/VPython-3.2.11 (Thanks to Martin Mason for changes needed for Python 2.4+.)
EMWave-Maxwell_v280.py tested with Python 2.6/VPython-3.2.11 (fixed bug with scene.ambient [2015-10-31])
Under development: VPython projects (led by Rob)
Relativity
Visualizing Proper Time in Special Relativity
Tensor Calculus and Differential Forms
(under development)
This demonstrates the addition of two covectors (two "1-forms") via
the "co-parallelogram rule".
Aa
+
Ba
=
Ca
(2008) VPython with Real-Time Data [with Tav Hawkins]
- (06/20/2008) VPython with real-time Wiimote data (head tracking with the IR-camera)
headtrack-Wiimotelib121-PY24.py
tested with Python 2.4/VPython 3.2.9
|
The inspiration for this project came from
the efforts of
Johnny Chung Lee - Projects - Wii.
In order to read in the real-time data from the the Wiimote,
we use the procedure presented by
Nishio Hirokazu,
which uses Brian Peek's (Windows-only)
WiimoteLib v1.2.1 [a library for using a Nintendo Wii Remote (Wiimote) from .NET.]
described in
"Code4Fun - Managed Library for Nintendo's Wiimote (Brian Peek)".
To use .NET with Python,
we used Brian Lloyd's Python for .NET.
Ideally, we would have liked to use the latest versions of
the various software packages [which should be possible].
However, for now, the combination of versions that worked for us
[with our program] is:
I'm sure there is a platform-independent solution
in which
Python communicates directly with Bluetooth.
Of course, one now needs to know details of the protocol
for talking with the Wiimote.
Note: This was just thrown together as a proof of concept.
The code isn't the prettiest. The tracking and the visualization could certainly be improved.
|
Some Hardware details:
I bought two LED-flashlights (less than $5 each) and replaced the LEDs with
IR-LEDs from DealExtreme.
I mounted the flashlights onto a pair of safety goggles. (The first version is pictured here.)
The Wiimote is sitting on top of my monitor, pointing toward me.
[Note, I only use the Wiimote. I don't have a Wii console.]
My current version uses
IR-LEDs from Radio Shack
[which seem to have a better viewing angle]
and
two
MAGLITE Solitaire flashlights
[found at Walmart] which feature replaceable LEDs.
So, no soldering is needed! However, since my standard-size LEDs were too big,
I had to leave off the moveable mirror/cover used to adjust the beam.
If you don't have these IR parts available, you can try using a
pair of standard (IR-based) remote controls. By the way, it's helpful to
use your typical webcam or cameraphone to see the IR light to check that the LEDs
are hooked-up correctly.
|
- NEW! (07/15/2008)
VPython with real-time Wiimote data (3-axis accelerometer)
accelerometer-Wiimotelib121-PY24.py
tested with Python 2.4/VPython 3.2.9
|
After pairing your Wiimote with your computer's Bluetooth radio,
your Wiimote's three-axis accelerometer readings are represented by an arrow.
(Think of the accelerometer as "a small sphere suspended by
identical springs attached to the corners of a cube".)
When your Wiimote is sitting normally upright on your desk, it will read a_z=1.
(The small sphere is displaced downwards, and the net force on the sphere
due to the springs is upward.)
When your Wiimote is in freefall (and not rotating), it will read zero.
To show this, gently toss (without rotation) your Wiimote to someone.
When the accelerometer value is small enough, the background color of the
scene changes to white (since the corresponding small arrow is hard to see).
|
- VPython with real-time Vernier Go!Motion data (ultrasonic ranger)
(soon)
| |
- VPython with real-time data with NeatTools and Mindtel TNG-3B
|
VPython with the Wiimote
(based on our presentation at
AAPT09Sum-AnnArbor)
(more information will be added to this section)
This is an update of our
earlier version [for Python 2.4 / VPython 3.2.9 / WiimoteLib 1.2.1 / Python for .NET 1.0 ] from above.
For Windows XP and Vista... (checked with XP SP3 and Vista64)
- Download and install
Python 2.5 and VPython 3.2.11
(You can also try Python 2.6 and Visual 5.
I haven't tried "Python 2.5 with Visual 5".)
- To get data from the Wiimote,
you need Brian Peek's
WiimoteLib library using .NET
(which is the library used for
Johnny Chung Lee's Wiimote projects,
as well as many others).
The latest stable version is
WiimoteLib 1.7.
(Alternatively, for partial support of the
Wii MotionPlus extension, try
WiimoteLib 1.8 beta.)
The only file you need from the downloaded package is WiimoteLib.dll.
(It is helpful to also use WiimoteTest.exe to see all sorts of data from the wiimote.
You'll find documentation
for the library, WiimoteLib.chm, in the docs/ folder. )
- To get Python to talk to WiimoteLib, you need
Python for .NET 2.0,
which provides clr, an interface to the .NET Common Language Runtime.
Unfortunately,
the file pythonnet-2.0-alpha2.zip only works for Python 2.4.
Fortunately, Feihong Hsu
figured out that one can compile the
Python for .NET source code
and tweak switches to make it work in Python 2.5 and in Python 2.6.
In the end, all you need are the two files
Python.Runtime.dll
and
clr.pyd
placed in the Python folder (e.g. C:\Python25 ).
- In summary:
- In your Python installation folder, Python.Runtime.dll and clr.pyd.
- In the folder with your Python program, WiimoteLib.dll.
VPythonWiimote-examples.zip
contains some example programs
(including the required library files mentioned above).
(Tested for Python 2.5/VPython 3.2.11.
Some modifications may be needed
for Python 2.6 or for Visual 5.)
- Possibly useful:
flexible tripods
- ...to be continued
|
[more to come!]
VPython applications (up)
Programming Notes
Using Python 2.3
Here's a registration-file for Windows 2000 and Windows XP
that will fix that problem with the IDLE editor closing completely
when terminating an animation you are working on.
Python-File-new.reg
It assumes that you installed Python in the C:\ drive.
If so, you may just "Open" it.
Otherwise,
download [Right-click->Save Link to...]
the appropriate pair to your desktop, then after reading the .reg files and making any desired changes,
merge with your registry.
Then, "Merge" it by double-clicking on it.
If you mess up, you can try to clean things up in Explorer
via Tools->FolderOptions->FileTypes...->PY Python File->Advanced
..or else use regedit.
Use at your own risk! (Backup your registry before merging!)
|
Using Python 2.3 and Python 2.4
These registry hacks to allowed me to select which VPython version is used to execute a .py file.
They may work for you.
Use at your own risk! (Backup your registry before merging!)
Download [Right-click->Save Link to...]
the appropriate pair to your desktop, then after reading the .reg files and making any desired changes,
merge with your registry.
My Python installations are on the F:\ drive:
If your installations are on the C:\ drive, use:
If you mess up, you can try to clean things up in Explorer
via Tools->FolderOptions->FileTypes...->PY Python File->Advanced
..or else use regedit.
Use at your own risk! (Backup your registry before merging!)
|
This program demonstrates a subtlety in the copyobjects() function
on
http://www.vpython.org/webdoc/visual/options.html
copyobjects-subtlety.py tested with VPython23-2003-09-18
Working example of an improved copyobjects()
and a new updatecopyobjects().
copyobjects-example.py tested with VPython23-2003-09-18
related sites:
VRML Gallery of Electromagnetism
The Light Cone