# Finding the angle and velocity to hit a target in t seconds

My goal is to compute an angle + velocity combination to hit a target at point $(x,y)$ in exactly $t$ seconds. (Uniform gravity, no drag, no wind)

I know that the general formula for trajectory is:

$x = vt \cos \theta$,

$y = vt \sin \theta - \frac{1}{2} g t^2$.

But the problem is I think I can't solve the equation with only 2 inputs, $x$, $y$ and $t$.

Any ideas would be gladly appreciated, thank you for your brain time.

-
I believe this is related to projectile motion and should be there in any fundamental physics textbook. –  dineshdileep Jan 9 '13 at 10:56

Note that $(v t\cos(\theta))^{2}+(vt\sin(\theta))^{2}=v^{2}t^{2}=x^2+(y+\frac{1}{2}gt^{2})^{2}$ which gives $$v=\frac{\sqrt{x^2+(y+\frac{1}{2}gt^{2})^{2}}}{t}$$ Now it is fairly easy to get $\theta$ from $x=vt\cos(\theta)$.

-
Did you ever convert this to code? –  Matt W Jul 16 '13 at 9:33
No. But that should be fairly easy... –  Dominik Jul 16 '13 at 16:08
How about this: brackets = y + .5 * g*t ^ 2; equation = (x^2) + brackets^2; v = math.sqrt( equation ) / t; –  Matt W Jul 16 '13 at 16:20
I'm just not sure how to get theta from 'x=vt cos(theta)' –  Matt W Jul 16 '13 at 16:22

From the first equation,

$$v t = \frac{x}{\cos{\theta}}$$

Plug this into the second equation:

$$y = x \tan{\theta} - \frac{1}{2} g t^2$$

Rearrange and solve for $\theta$. Then use the first equation to solve for $v$. Use the fact that

$$\cos{\tan^{-1}{z}} = \frac{1}{\sqrt{1+z^2}}$$

-