College-Prep Physics: I’ve been coding with my AP Physics classes for years. But in honor of this week’s Hour of Code, I tried VPython programming for the first time with my College-Prep class. We used the GlowScript version of VPython, which can now run regular VPython code inside a browser. Nothing to install!
Why are we coding in physics class?
I asked the students if they had ever seen the first Toy Story movie:
Realistic motion is often too complicated for animators to do by hand, says Michael Kass, a researcher at Pixar Animation Studios. “The results can be awful and very expensive.” He points to the original 1995 Toy Story and notes that “if you see a wrinkle in clothing, it’s because an animator decided to put in a wrinkle at that point in time. After that we [at Pixar] decided to do a short film to try out a physically based clothing simulation.”
(excerpt from “Animation uses old physics to new effect” in Physics Today)
Then I showed this simple cloth physics engine:
Next, we watched these short clips showing more advanced modeling of clothing, hair (from Tangled), and snow (from Frozen).
Now it was time for the students to tinker with some code which modeled our red and blue constant velocity buggies. Rather than have them do a tutorial from scratch, I gave them a pre-written VPython program and asked them to make changes in order to create different outcomes. They worked in pairs, and I circulated around the room stamping their sheets as they accomplished each task. (The ♢♢ tasks require them to apply what they learned from the ♢ tasks.) Often there is more than one way to do each task.
For more info on how to incorporate programming and computational physics into an introductory physics course, I highly recommend reading this article:
Chabay, R. & Sherwood, B. (2008) Computational physics in the introductory calculus-based course. American Journal of Physics, 76(4&5), pp. 307-313. (Available here.)
NGSS Science and Engineering Practices:
#5. Using mathematics and computational thinking
AP Physics C: Yesterday, students took their data from the falling coffee filter lab and created a model of it in VPython. The terminal velocity of the filters in their computer model should match that of their experimental data.
We’ve been having a some computer issues with installing VPython on the school computers, and so pair programming has slowly evolved into groups of 3 and 4. I decided to check out GlowScript again and discovered that it now uses RapydScript, which means the code is almost identical to Python. There are some difference in how the 3D shapes are defined, but it’s not a big deal with the online reference at your side. I tried to code the coffee filter program myself in GlowScript. Based on how close the code is to VPython, I’m seriously considering switching over to GlowScript for the rest of the year. I showed the program in class today, and they liked the in-browser aspect of GlowScript.
You can see my code for the coffee filter program here: Falling Coffee Filter.
NGSS Science & Engineering Practices:
#2. Developing and Using Models
#5. Using Mathematics and Computational Thinking
AP Physics C: Intro to Magnetic force on moving charge (shown without sound):
Also played with VPython program showing charged particle moving in B-Field:
- What determines the force on the charge?
- changing B (magnitude, direction, parallel, perpendicular)
- changing q (magnitude, sign)
- changing v (magnitude, direction)
- Cross product & Right Hand Rule to determine direction of force.
The VPython program (and others) are available on the Matter and Interactions website page E&M Lecture Demo Programs.
AP Physics C: Students were tasked with writing a program in VPython or GlowScript to model the electric field around a dipole. Here’s my GlowScript program. (In GlowScript programs, rotate the camera by dragging with the right mouse button, or hold down the Ctrl key and drag. To zoom, drag with the left+right mouse buttons, or hold down the Alt key and drag, or use the mouse wheel.)
AP Physics C: Today we looked at AP 2000 E&M #2 — charges in a equilateral triangle. According to the problem, there are TWO points were E=0 along the altitude of the triangle. I wrote a Glowscript program to visualize and graph the electric field as the test charge rises from the base of the triangle to the the top.
GlowScript program: E-field of Equilateral Triangle
Next week when students write a program to display the E-field around a dipole, students will have the option to do this scenario instead.
AP Physics C: We talked about work done by a non-constant force, using an example of a 1000-kg space rock falling to the surface of the Earth from a distance of 10 earth radii from the center of the earth. Without telling them how to approach the problem, I wanted to see what they would do on whiteboards first. A couple groups incorrectly assumed the force was constant the whole time. Other groups realized the force wasn’t constant and tried to figure out some kind of “average force” to use — one group used the force at the halfway point as the average force while another group averaged together the forces at the initial separation and final separation. Neither approach works well, so we talked about breaking the problem up into many small steps. That’s when wrote a program in VPython/Glowscript to automate that brute force method (program above, output below). We also played around with the step size to see the effect on the accuracy of the answer. How big could the step size be and still have an acceptable answer?
Then we solved the same problem using calculus. Answer below.
And we get the same answer … hooray!
I really like using VPython for these kind of problems because it really helps kids think about integration as sum of very tiny parts
AP Physics C: Students programmed a visualization of gravitational force between a spacecraft and a planet. It’s a great exercise that helps emphasize its vector nature, where the negative sign in the universal gravitational force equation vibes from, and unit vectors.
Bonus: The screenshot is taken from my phone! Glowscript (a web-based version of VPython) works in the Chrome browser on my Android 4.2.2 phone.