1

I am working on a simple 2D computer game. In the game, I have a 'robot' that throws a ball towards another robot, in the shape of a parabola. Both 'robots' are positioned on the x axis, aka their y co-ordinates are the same.

The program knows the positions of the two robots, and it knows the position of the vertex.

enter image description here

As I said, 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. (Or is there a better way to do this?)

If so, how can I calculate the y position of the ball at any given time, as I said while knowing the location of the parabolas' vertex, and knowing it's two points of intersection with the x axis?

Thanks

EDIT: Please try to make your answers as clear as possible, since my math knowledge is very basic. Thanks

user3150201
  • 543
  • 2
  • 5
  • 15

1 Answers1

1

If the robot separation is $S$ and the vertex is at $H$ height then

$$ y(x) = \frac{4 H}{S} x - \frac{4 H}{S^2} x^2 $$

The horizontal velocity is constant, or $x(t) = v_x t$, so as a function of time the above is

$$ y(t) = H \left( \frac{4 v_x}{S} t - \frac{4 v_x^2}{S^2} t^2 \right) $$

ALso note that the initial verical velocity is $ v_y = \frac{4 H}{S} v_x $ which leads to the expression of what is the horizontal velocity if the thowing speed $v$ is known:

$$ v_x = \frac{S}{\sqrt{16 H^2+S^2}} v $$

(this arises from $v=\sqrt{v_x^2+v_y^2}$)

John Alexiou
  • 13,816
  • Thanks for answering. I tried the first equation that you wrote, and it works :) But I would like to understand this equation. Could you try explaining it to me? Why 4? Why S squared? Please try to explain in a simple language so I will be able to understand. – user3150201 Jan 16 '14 at 13:40
  • I took a general parabola $y = C_0 + C_1 x + C_2 x^2$ and fitted the points $(0,0)$, $(S,0)$ and $(\frac{S}{2},H)$. That is all. You can rewrite the equation as $$\frac{y}{H} = 4 \frac{x}{S} \left(1-\frac{x}{S}\right)$$ with the rhs varying from 0 to 1. – John Alexiou Jan 16 '14 at 13:59
  • Sorry, tried your formula again and I'm not sure it works. Maybe I don't understand something. H is the Y co-ordinate of the vertex - right? And S is the distance between the parabola's two intersects with the x axis? – user3150201 Jan 16 '14 at 16:02
  • Correct. If you plot it out you will see it works as advertised. – John Alexiou Jan 16 '14 at 17:09