How to know 2 unknown variables using 2 equations?

153 Views Asked by At

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$?

2

There are 2 best solutions below

0
On BEST ANSWER

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.

4
On

Hint: Divide both equations and you will get

$$\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)}$$