I need to calculate the initial velocity required to launch a projectile at a given angle from point A to point B. The only force acting on the projectile after launch will be gravity – zero air resistance. The projectile is launched within a simulated, virtual environment; however, I am asking for help with the physics rather than the simulation itself.
I have had success (with a different equation) when point A and point B are at the same height; however, once point B is at a different height, my calculations become less precise – well, wrong in fact.
I researched the following formula for finding the range of a projectile on uneven ground. The parameters are all available to me, except the initial velocity that I need to solve for.
$d$ : range or distance
$v_i$ : initial velocity
$g$ : gravity
$\theta$ : launch angle
$y_0$ : launch height
$$d = \frac{v_i \cos\theta}{g}(v{_i} \sin \theta + \sqrt{(v_i \sin\theta)^2 + 2gy_0})$$
I attempted to solve for initial velocity (eq: A):
$$v_i = \sqrt{\frac{d^2g}{2\cos\theta^2(y_0+d \tan\theta)}}$$
Using this equation in my simulation I apply the velocity to a normalised displacement vector and launch the projectile. It gets close to its target but:
- $x_{final}$ is always correct
- $z_{final}$ is always incorrect - it is close to the desired $z$ but always offset by a seemingly proportional amount.
I have spent many hours trying to review the equation but I have been unsuccessful. Any advice would be most appreciated:
- is this the correct equation?
- have I solved for $v_i$ correctly? I have looked for an example equation online but I have not found one structured how I need it, i.e. solving for $v_i$
- I have spent hours researching online - perhaps I have missed some good (but entry-level) resources. Do you know of any reference material that may help me?
Update - I have now named the equation above for referencing below
Following on from the answer by @Pygmalion, which I am still gratefully working to understand:
I agree that your derived equation is equivalent to mine (A). Using yours (@Pygmalion's) in my simulation, I therefore observe the same failures: the projectile always lands short of the target.
I have simplified the simulation keeping the launch height and target height the same. I still encounter the same problem with equation A; however, when passing the same parameters to the following equation the projectile always hits the target precisely (eq: B):
$$v_i = \sqrt{\frac{dg}{\sin2\theta}}$$
Given the success of equation B when the launch and target heights are the same and the failure of equation A given the same conditions, I question whether equation A is the correct one to solve the problem since I would expect it to work for any combination of launch|target height.
I think the help I need is around why equation B works. Does it cater for conditions that equation A overlooks? If equation A is unsuitable, are you able to recommend an alternative?
In short, the $v_i$ calculated by equation A (in my simulations) is always less than $v_i$ from equation B given the same inputs - the projectile therefore always falls short of its target.