FearOfPhysics.com: Create computer movies with physics

Using Physics to Create Computer Animations

Do you want to learn to create computer animations based on physics? Here's an example:

It shows shows a ball moving in an airless world, with an acceleration of 9.8 m/s2. Its motion is entirely predicted by the laws of physics.

Would you like to try creating such movies for yourself? If so, read on...

TEACHERS! This is a great project-based activity for your students to try!


Step 1: Get the free book

The fearofphysics editors have assembled a free book on how all of this works. We've summarized a few steps below to help you get started.

Step 2: Install needed software

The open source software we use here is called Povray (povray.org), MegaPOV (http://megapov.inetart.net/), and ffmpeg (http://ffmpeg.org). Povray, MegaPOV, and ffmpeg were all written by the authors of the respective packages. The ffmpeg GUI was written by editors of this site.

Windows Users

Follow the steps in Section 2.2 of the book, which say...
  1. Download Povray from Povray.org.
  2. Download physics.inc (right click on the link) and copy it into the folder called "My Documents > Povray > v3.6 > include.” That is, copy physics.inc into the folder called "include," which is buried in "My Documents > Povray, etc."
  3. Download the image to mp4-movie stitcher. There are a few files in this zip archive. Wherever you copy it on your computer, do not separate the files.

OSX Users

Follow the steps in Section 2.3 of the book, which say...
  1. Download MegaPOV from here, which is a custom configuration of MegaPov we assembled for making physics movies.
  2. Drag the folder out of the dmg packages, and onto your desktop or Applications folder.
  3. Download the image to mp4-movie stitcher. There are a few files in this zip archive. Wherever you copy it on your computer, do not separate the files.
  4. Following the two configuration steps in Section 2.3.1 of the book.

Step 3: Test your software

To make sure everything is installed properly, type this code into the Povray or MegaPOV text window.

#include "physics.inc" camera { location <0,0,-20> look_at <0,0,0> } light_source { <0,0,-50> color White } sphere { <0,0,0>,1 pigment {Red} } draw_vector(<0,0,0>,<3,3,0>,Green,"hi")

Then render the image. If everything is installed properly, this image should appear:

If this image does not appear, be sure you've type in the code properly and you carefully followed all steps in Section 2.2 (Windows) or 2.3 (OSX) of the book above.

Step 4: Create your first animation

Our animation technique is based around a common code-base that we call the "skeleton code." You can download it here. To use it, paste it into Povray or MegaPOV and then:

Here's a video tutorial that uses the "skeleton code" to make a red ball move around the screen.

Here's the skeleton code. Note it sets up a light source and camera (needed by the ray tracer), as well as an initial position and velocity of the object (pos and vel). An acceleration is set (just below the #while statement), and the physics equations follow. Final drawing based on pos and vel appear after the #end statement, in this case a red sphere with a radius of 1.

#include "physics.inc" camera { location <0,0,-15> look_at <0,0,0> } light_source { <-0,0,-20> color White } #declare pos = <0,0,0>; #declare vel = <0,0,0>; #declare dt = 0.1; #declare xtime = 0.0; #while(xtime <= clock) #declare a = <0,0,0>; #declare pos = pos + vel*dt + 0.5 * a * dt * dt; #declare vel = vel + a *dt; sphere { pos,0.1 pigment {Yellow} } #declare xtime = xtime + clock_delta; #end sphere { pos,1 pigment {Red} } draw_vector(pos,vel,Green,"v") draw_vector(pos,a,Yellow,"a")

This should render a red ball that just sits there. To make it move, change the vel=<0,0,0> like to vel=<5,0,0>. Also, try vel=<0,0,5> or vel=<0,5,0>.

This skeleton code is tightly linked to the logic that physics demands. Here's what each part of the code does:

Step 5: Things to try

Here are some more things you can try with the skeleton code above:

  • Change the vel=<0,0,0> to vel=<1,0,0> and the a=<0,0,0> to a=<2,0,0>
  • Leave the vel=<0,0,0> and change the a=<0,0,0> to a=<5,0,0>
  • Leave the vel=<0,0,0> and change the a=<0,0,0> to a=<-5,0,0>
  • Change the vel=<0,0,0> to vel=<5,0,0> and the a=<0,0,0> to a=<-2,0,0>
  • Change the vel=<0,0,0> to vel=<-2,0,0> and the a=<0,0,0> to a=<2,0,0>
  • Change the vel=<0,0,0> to vel=<0,5,0> and the a=<0,0,0> to a=<0,-9.8,0>

These are examples of how changing the velocity (vel) and acceleration (a) on an object can affect its motion.

What next?

We encourage you to read through our book, perhaps in this way:

  • If you are learning physics, read Chapter 1 for the how's and why's on this.
  • To learn what a "vector" is and what the <0,0,0> notation means, read Chapter 3, Section 3.3.
  • To learn about what you can draw (and how), read Chapter 4.
  • To learn more about making animations based on physics, read Chapter 5.
  • To learn how the structure of the skeleton code above, read Section 5.4.
  • To learn about what physical objects you can draw (springs, ropes, etc.) read Chapter 8.
  • For ideas on what to do next, start with the "Projects" in Chapter 9. Go to the next chapters from there.