[Edu-sig] Python in physics class
Sun, 28 May 2000 16:19:28 -0400
> I'm a high school physics teacher, and I'd like to try some Python
> programming in my class next year. Be advised, I teach the
> math-lite version of our physics class.
> I'm thinking that some basic programming would be an interesting way to
> introduce some of the mathematical reasoning and methods that
> they'll need.
I'm developing "Visual," a 3D graphics library for Python that will be used
next year for student programming in the "Matter and Interactions"
introductory physics course at Carnegie Mellon University (see
http://cil.andrew.cmu.edu/mi.html). Matter and Interactions is a college
course that is more advanced than your "math-lite" high school course, but
Visual is designed to be as easy to use as possible.
Here's a Python program for a 3D animation of a bouncing ball. Notice the
lack of explicit graphics code, apart from the creation of the "floor" and
from visual import *
floor = box(length=5, height=0.5, width=5, color=color.purple)
ball = sphere(pos=(0,4,0), color=color.red)
ball.velocity = vector(0,-1,0)
dt = 0.01
ball.pos = ball.pos + ball.velocity*dt
if ball.y < 1:
ball.velocity.y = -ball.velocity.y
ball.velocity.y = ball.velocity.y - 9.8*dt
Notice that ball.pos and ball.velocity are vectors; Visual's vector type
takes care of the details of vector arithmetic. rate() is a helpful
function that limits the number of simulation steps per second, so that the
animation runs at the same speed on all machines.
A public alpha release of Visual, complete with physics-oriented example
programs, will be available within a few days. Since we need to provide
students with a single installer, Visual will come packaged with its own
Python 1.5.2 installation and a version of IDLE modified to suit our needs.
A bare module will also eventually be available.
Visual currently runs on Windows and Linux, and we are planning a (hopefully
"well-supported," Kirby :) Macintosh version as well.
I'll post a link when I have one.