tags:

views:

127

answers:

3

Hi, I have xy co-ordinate like (200,200). I know the angle calculation from the origin the ball throws. How can I find the initial velocity to reach that particular xy co-ordinate when ball is thrown in 2d Environment?

Iam using

 x = v0cosq0t;
 y = v0sinq0t - (1/2)gt2.

but time is needed. Without time can I do it? any help please?

A: 

Im sure you can assume the velocity change is instantaneous. Games physics always has some 'dodgy' parts in it because it is too computationally expensive or not important enough to get right down the low granularity information.

You can start the velocity ass instantaneous, and then using a timer class to measure then time between each frame (very rough way of doing it), or you can have a timer class set up in an update loop that will update the physics every x seconds.

Craig
A: 

You can eliminate v by multiplying x equation by sin and y equation by cos and subtracting.

You now get a quadratic in t which you can solve and once you have the formula for t, you have a formula for v. All this you do on a whiteboard and get the formula.

So you don't need to calculate t, as you can (manually) derive a formula for v, which only involves x,y, cos and sin.

Moron
+1  A: 

I'm assuming that you want the ball to hit that specific point (200,200) at the apex of its path. Well, my physics is a bit rusty, but this is what I've thrown together:

v_y = square_root(2*g*y),

where g is a positive number reflecting the acceleration due to gravity, and y being how high you want to go (200 in this case).

v_x = (x*g) / v_y,

where x is how far in the x direction you want to go (200 in this case), g is as before, and Vy is the answer we got in the previous equation.

These equations remove the need for an angle. However, if you'd rather have the velocity + angle, that's simple:

v0 = square_root(v_x^2 + v_y^2)

and

angle = arctan(v_y / v_x).

Here is the derivation, if you're interested:

(1/2)at^2 + v_yt + 0 = y

(1/2)at^2 + v_yt - y = 0

by quadratic formula,

t = (-v_y +/- square_root(v_y^2 - 2ay)) / a

we also have another equation, because at the apex the vertical velocity is 0:

0 = v_y + at

substitute:

0 = v_y + (-v_y +/- square_root(v_y^2 - 2ay))

0 = square_root(v_y^2 - 2ay)

0 = v_y^2 - 2ay

v_y = square_root(-2ay), or

v_y = square_root(2gy)

For v_x:

v_x*t = x

from before, t = v_y / a, so

v_x = (x*g)/v_y

I hope that made enough sense.

giogadi
you are a physics Diamond !!!!!!!!!!
Mikhail Naimy