# Modeling the motion of a bouncing ball

I'm writing a program that displays a line of text, and animates a ball that bounces from syllable to syllable (like a sing-along). The program knows the location of each syllable, and it knows at what time the ball should be at each syllable.

I have a set of equations that work OK, but not great. I came up with them a few years ago after much googling and stumbling about. They take the location of the previous syllable ($x_0$, $y_0$), the location of the next syllable ($x_1$, $y_1$), the time t (from start 0 to finish 1), and compute where the ball should be ($x$, $y$):

$$d = x_1 - x_0$$ $$v = d/t$$ $$h = 5 + 0.3 |d|$$ \begin{align} x(t) &= x_0 + v t\\ y(t) &= y_0 - h + \left[4 \frac{h}{d^2} \left(\frac{|d|}{2}- |v| t \right)^2 \right] \end{align}

What I would like is a better set of equations that more accurately model the motion of a bouncing ball. A ball with a mind of it's own, I suppose, as it does need to change speed and direction with each new syllable.

• Maybe I'm wrong, but it seems to me that you'd want to use projectile equations of motion, rather than a bouncing ball. Getting a proper $v$ might be a bit trickier, but maybe more physically right this way? Commented Jan 17, 2015 at 21:37
• Conservation of momentum might invalidate your ball switching directions... Commented Jan 17, 2015 at 21:37
• @KyleKanos projectile equations look promising. I think I would need to define v and theta in terms of d, but I'm at a loss for how to do that. Commented Jan 17, 2015 at 21:44
• You'd need to specify the angle, but it can be done: $d=v^2\sin(2\theta)/g$ (the link uses $d=R$). Commented Jan 17, 2015 at 22:01

You need the position of the ball $(x(t)$, $y(t))$ for $0<t<1$ if at $t=0$, the ball was thrown with initial velocity $(v_x,v_y)$ at the position $(x_0,y_0)$ in a gravitational field of acceleration $\overrightarrow{a}=(a_x,a_y)=(0,-g)$. The velocity has to be calibrated in order to make the ball arrive the point ($x_1,y_1$) at $t=1$.

The position of the ball is given by

$$x(t)=x_0 + v_x t$$ $$y(t)=y_0 + v_y t - g\frac{t^2}{2}$$

We want to obtain $(v_x,v_y)$ to get $x(t=1)=x_1$ and $y(t=1) = y_1$, so,

$$x(t=1)=x_0 + v_x = x_1$$ $$y(t=1)=y_0 + v_y - \frac{g}{2} = y_1$$

and therefore,

$$v_x = x_1 - x_0$$ $$v_y = y_1 - y_0 + \frac{g}{2}$$

and finally, your movement equations are:

$$x(t)=x_0 + (x_1 - x_0) t$$ $$y(t)=y_0 + (y_1 - y_0 + \frac{g}{2}) t - g\frac{t^2}{2}$$

• Thanks, that totally did the trick! I really appreciate having a solid equation behind this, and not whatever it was that I had mangled into working before. One thing I noticed is that with these equations the ball always reaches the same highest point. I'd like the ball to go higher for longer distances, and lower for shorter distances, so I vary g based on distance. I found that g = 3 * |x1 - x0| works well for my particular use. If there happens to be a better way to accomplish that I'd love to know. Thanks again! Commented Jan 18, 2015 at 3:21
• What you can do is to obtain the above equations by taking x(t')=x1 and y(t')=y1. So, now 0<t<t'. You can then choose t' arbitrarily. The greater t' is, the higher the ball will go. Therefore, you can choose t' proportional to |x1-x0|, this is, t' = K|x1-x0|, and calibrate K until the highest point the ball reaches is satisfactory to you. Commented Jan 18, 2015 at 23:28