# How can I compute the movement of an object along a parabola?

I am working on a simple 2D game. In the game, I have a 'robot' that throws a ball towards another robot, in the shape of a parabola. Both 'robots' have the same Y coordinate.

The program knows the positions of the two robots, and it knows the position of the parabola's apex ('vertex') as shown here: I need the ball to travel along the parabola. This means (correct me if I'm wrong), that at any given time, I need to be able to calculate the Y position of the ball, since I know it's X position.

If so, how can I calculate that Y position at any given time, knowing the information above. Please try to make your answers as clear as possible, since my math knowledge is very basic.

• Are you looking for the Angle and Power to throw at? Or the Velocities in X and Y to throw at? – MickLH Jan 16 '14 at 15:13
• Also, can you be more specific about what "Vertex" is, is it always the top of the curve, or will it be on the side sometimes? – MickLH Jan 16 '14 at 16:13
• @MickLH It's always the top of the curve. – user3150201 Jan 16 '14 at 18:04

So you're looking for a parabolic function y(x) that equals zero at two known points. Let's call those points r1 and r2, after robots 1 and 2. One solution is easily found:

y(x) = ( x - r1 )( x - r2 )

On top of the robots, one of the terms in parentheses becomes zero, which, multiplied by something else, remains zero. For that reason, we can multiply the entire thing by a factor a. This stretches the parabola vertically (or flips it upside down for negative values) without changing the location of the zeroes. We manipulate a to make sure the curve passes through the vertex, defined by coordinates (xv, yv). We solve the following equation for a:

y(xv) = yv

a ( xv - r1 )( xv - r2 ) = yv

This yields:

a = yv / (( xv - r1 )( xv - r2 ))

We get the function y(x) we want by multiplying our original function with the scaling factor a we just obtained:

y(x) = ( x - r1 )( x - r2 ) yv / (( xv - r1 )( xv - r2 ))

If we are talking about projectiles here, and you know the X position, though it can simply be calculated: Where d is the horizontal distance from the launch point.

You can simply calculate the y at distance x this equation: Where:

• x is the x position.
• theta is the angle with the ground.
• g is the gravity constant.
• v is the velocity .