Archive | VPython RSS for this section

Day 65: Hour of Physics Code

wpid-img_20141211_121530354_hdr.jpg

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:
http://andrew-hoyer.com/experiments/cloth/

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.

Resources:

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

Day 42: Modeling a Falling Coffee Filter in GlowScript

fallingfilter3

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

Day 131: Moving Charge in a Magnetic Field

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:

MagneticForceVPython

  • 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.

Day 98: Electric Field Around a Dipole

dipolepython

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.)

Day 93: An Interesting Electric Field

efield

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.

Day 30: Brute Force Computations vs. Calculus

Work by gravity Glowscript

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?

Work by gravity OUTPUT Glowscript

Then we solved the same problem using calculus. Answer below.

Work by gravity OUTPUT WolframAlpha

 

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

Day 18: Gravitational Force in VPython

image

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.

Day 155: Temperature vs. Wavelength

PhotoGrid_1369091321078College-Prep Physics: I had a clear 250-W bulb plugged into an variac and slowly increased the voltage from 0 to 120 V. We saw the color of the glowing filament change from red to orange to yellow to white. The temperature and the brightness of the filament increased as well. Now that we have a way of measuring the color of light (by its wavelength), we can look for a mathematical relationship between the temperature of the glowing filament and the peak wavelength of the light emitted. We used a blackbody applet to collect data: http://bit.ly/blackbodysim.

bifurcation

AP Physics C: Students wrapped up their investigation of Val’s grouse, concluding with the creation of a bifurcation diagram. Here’s a bifurcation program I made in GlowScript.

Conceptual Physics: Students continued work on their bike light presentations. Some groups used http://circuitlab.com to make professional-looking circuit diagrams for their presentations.

Day 154: Chaos and Valentine’s Grouse

grouse2AP Physics C: We finished reading Arcadia and began exploring the (sometimes chaotic, sometimes predictable) behavior of a simple logistic equation for modeling animal populations. The handout is here: Valentine’s Grouse: An Exploration of Chaos in Populations. And you can explore it yourself using my version of the population program in GlowScript.

College-Prep Physics: Wrapped up the wave/buggy lab from yesterday. We determined the model for our data to be wavelength = speed / frequency.

Conceptual Physics: Students finished building/testing their bike circuits and began drawing and annotating their final circuit diagrams.yB2SEJYMDMyaN6DHJ72N65aE

Day 143: Curly Electric Fields

FaradayVPython

AP Physics C: Today we started our discussion of Faraday’s Law. I used a great VPython program to illustrate how a steadily changing magnetic field produces as constant curly electric field. The light blue arrows show the solonoid’s magnetic field. The black arrow indicates the direction of the current in the solonoid. The dark blue arrows show the magnetic field through wire ring. The purple arrow shows the direction of the rate of change of the magnetic field through the ring. And the orange arrows show the non-coulomb curly electric field along the ring. This program, and lots more, are available in the instructor’s resources section of the Matter and Interactions website: http://matterandinteractions.org/Content/Materials/materials.html

College-Prep Physics: We did a formal recap of what we learned from the light intensity lab and gravitational force lab. Inverse square laws! Then students did some more WebAssign work on light and gravity.

Conceptual Physics: Students took a quiz on Chapter 13 (Generators and Diodes).