1
\$\begingroup\$

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:

enter image description 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.

\$\endgroup\$
3
  • \$\begingroup\$ Are you looking for the Angle and Power to throw at? Or the Velocities in X and Y to throw at? \$\endgroup\$
    – MickLH
    Jan 16, 2014 at 15:13
  • \$\begingroup\$ 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? \$\endgroup\$
    – MickLH
    Jan 16, 2014 at 16:13
  • \$\begingroup\$ @MickLH It's always the top of the curve. \$\endgroup\$ Jan 16, 2014 at 18:04

2 Answers 2

2
\$\begingroup\$

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 ))

\$\endgroup\$
1
\$\begingroup\$

If we are talking about projectiles here, and you know the X position, though it can simply be calculated:

enter image description here

Where d is the horizontal distance from the launch point.

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

enter image description here

Where:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .