3
//Calculate the velocity needed to throw the object to the target at specified angle.
float projectile_Velocity =
            target_Distance / (Mathf.Sin(2 * firingAngle * Mathf.Deg2Rad) / gravity);

Which formula is used to derive this projectile code?

House
  • 73,224
  • 17
  • 184
  • 273
systemdebt
  • 211
  • 1
  • 5
  • 17

1 Answers1

3

The formula comes from the combination of one of the equations of linear acceleration (v=u+at), v =d/t and components of velocity.

The vertical velocity component = vel*sin(ang). Using the equation of linear acceleration above with u=vel*sin(ang), v=-vel*sin(ang) and a=-g and rearranging for t we get the time for the projectile to hit the ground after being fired.

t = 2*vel*sin(ang)/g

Now using v=d/t (constant velocity formula) with the horizontal velocity component: v=vel*cos(ang), d=dist and t is as above we get the following:

dist =2*vel*vel*sin(ang)*cos(ang)/g
vel = sqrt(dist /(sin(2*ang)/g)) using the trigonometric identity that 2*sinx*cosx=sin(2x)

Which is almost what you got... Not sure why we have a square root difference. But that's where the formula is coming from anyways.

Uwais A
  • 156
  • 3
  • It was just so awesome :D :D Could not find it anywhere in deep ocean of web :) If it was possible, I would have liked it 10X times:) Thanks a ton :) – systemdebt Jul 18 '14 at 03:07
  • No problem, did you find out why we have a square root of difference in the answers? I'm just curious - can't see a mistake on my part, did you miss it out maybe? – Uwais A Jul 18 '14 at 03:11
  • My bad, I did not even notice it :D, I am still clueless about that part :) but still the direction you gave is satisfactory :) I am going to look for it and if I do get to know, i will definitely get back here, you too please just comment here if you get to know :) Thanks – systemdebt Jul 18 '14 at 03:41