Lesson goal: Computer animation with simple physics

Previous: Animate with laws of physics | Home | Next: Exploding text

After this lesson, why not add the effects of air? It is nearly impossible to do with pencil and paper, but very easy on the computer. Assume that air presents a deceleration on the ball opposite to $v$ given by $a_{air}=Cv^2$, where $C$ is some drag constant like $0.1$.

To use this, we need to know the direction in which the ball is flying at any instant. This is given by $\alpha=\tan^{-1}\frac{v_y}{v_x}$. If we know this flight angle, then the $x$ and $y$ deceleration components will be $a_x=a_{air}\cos(\alpha+\pi)$ and $a_y=a_{air}\sin(\alpha+\pi)$. Let's put this in, given that $\tan^{-1}\left(\frac{a}{b}\right)$ is math.atan2(a,b).

Now you try. Try fixing $\theta$, $v$ lines.

Type your code here:

See your results here:

This code will not run. You need to fill in some launch angle $\theta$ in the theta= line and some launch speed in the v= line. You can try experimenting with the drag constant, making it larger or smaller. You might make it $0$ and run it again at $0.01$ to compare the ranges of the two (i.e. it should go farther with no air drag). Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.