# How to know 2 unknown variables using 2 equations?

Trying to make my AI hit people. So I need a formula to know the time until my projectile will hit the target and also the direction the projectile should be shot at.

Here is an example scenario.

• The projectile shoots from the origin $$(0,0)$$
• Both projectile and target will move in a straight line.
• Speed of projectile: $$v = 2000$$ m/s
• Speed of target: $$u = 450$$ m/s
• Initial position of target: $$x = 6000$$ m, $$y = 0$$ m
• Direction target moves: $$b$$ (above $$+x$$ axis). $$b = 135^\circ$$

Unknown variables.

• Time projectile reaches target: $$t$$
• Angle of projectile: $$a$$

Here are 2 equations made from the data.

• $$(v \cos a)t = x + (u \cos b)t$$
• $$(v \sin a)t = y + (u \sin b)t$$

How do I get the $$t$$ and $$a$$, but mostly I just need the $$t$$?

The easy step is to eliminate $$a$$ by squaring your last two equations, and summing them up. You are using $$\sin^2 a+\cos^2a=1$$. You obtain $$v^2t^2=[(x+ut\cos b)^2+(y+ut\sin b)^2]$$ This is a quadratic equation in $$t$$, which is easy to solve. Make sure you use the positive solution.
$$\frac{\cos(a)}{\sin(a)}=\frac{x+u\cos(b)t}{y+u\sin(b)t}$$ and from here you can compute $$t$$ $$t=\frac{y\cos(a)-x\sin(a)}{u\sin(a)\cos(b)-u\cos(a)\sin(b)}$$
• $a$ is unknown. – Andrei Oct 6 '18 at 12:58
• I we have $t$ we can compute $a$ – Dr. Sonnhard Graubner Oct 6 '18 at 13:09
• What I meant to say is that in your approach you still have both unknowns ($a$ and $t$) in the same equation. – Andrei Oct 6 '18 at 13:12
• Now my solution have only $t$ in one equation. – Dr. Sonnhard Graubner Oct 6 '18 at 13:13