How to find directional vector to hit moving target

128 Views Asked by At

enter image description here

I am trying to find the directional vector to hit a moving target. For example, as seen in my drawing, Lets say a space ship at position Sxy needs to fire a projectile to hit the moving asteroid (currently at position Axy). The asteroid is moving with a linear velocity vector Av. The projectile has a constant speed (magnitude) of Ps. How can I solve for the projectile directional vector Pv? Both the asteroid and the projectile have a radius.

1

There are 1 best solutions below

1
On BEST ANSWER

With a radius, the solution isn't unique; it could be a glancing hit or a direct hit, depending on conditions. You could compute the span of angles, though this gets a bit trickier and I assume you didn't just want a glancing hit. If the make a trajectory where the object centers eventually would overlap, it will have definitely collide before that.

  1. Construct the position $X(t)$ of each object as a function of time.
  2. Set the positions to be equal at $t_o$ for overlap.
  3. Solve for $P_v$ then compute $t_o$ for the given velocity.

$$ X_A(t) = A_{xy} + A_v t\\ X_S(t) = S_{xy} + P_v t $$

$$ X_A(t_o) = X_S(t_o) \implies\\ (A_v - P_v)t_o = S_{xy} - A_{xy} := \Delta \implies \\ P_{v} = A_v - \frac{1}{t_o}\Delta $$

where you determine $t_o$ based on the known speed $\|P_v\|=P_s$.

$$ (A_{v,x} - \frac{1}{t_o} \Delta_x)^2 + (A_{v,y} - \frac{1}{t_o} \Delta_y)^2 = P_s \implies \\ a\ t_o^2 + b\ t_o + c = 0 $$

where $$ a := (P_s - A_{v,x}^2 - A_{v,x}^2)\\ b := 2(A_{v,x} \Delta_x + A_{v,y} \Delta_y)\\ c := - \Delta_x^2 - \Delta_y^2 $$

Then you just solve for $t_o$ $$ t_o = \frac{-b \pm \sqrt{b^2 -4ac}}{2a} $$

insert one of them into the expression for $P_v$ above.