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: