Mathematics – How to launch a ballistic projectile to hit a moving target, from the position and launch angle, position and speed of the target?

I suppose that your gravity acts on the vertical axis and that your launching angle corresponds to an altitude (measured vertically from the horizon, so 0 ° means a horizontal shot and 90 ° a right shot). Our turret is always free to rotate on the azimuth (side by side) to track the target and intercept it if it moves sideways.

The first thing to do is to take the absolute target position $ vec p_T $ and launch position $ vec p_L $ build a relative target position vector $ vec r $and its projection on the horizontal plane $ vec r_h $ and vertical axis $ r_v $:

$$ begin {align}
vec r & = vec p_T – vec p_L \
r_v & = vec r cdot vec {up} \
vec r_h & = vec r – r_v vec {up}
end {align} $$

This allows us to take the launch position right out of the equation. We can apply the 2nd and 3rd steps to the target velocity vector $ vec v $ to split it into a horizontal vector $ vec v_h $ and a vertical component $ v_v $.

Now, if we want to reach the target at an initially unknown time $ t $ seconds after launch we will have to cover the horizontal displacement $ vec r_h + vec v_h t $ in a straight line in time $ t $. So, the horizontal component of our launch speed $ vec l_h $ is:

$$ vec l_h = frac { vec r_h + vec v_h t} t $$

Given our desired launch angle $ theta $we know that the ratio between the horizontal and vertical launch speeds is:

$$ begin {align}
tan theta & = frac {l_v} { | vec l_h |} \
tan theta cdot | vec l_h | & = l_v \
tan ^ 2 theta cdot l_h ^ 2 & = l_v ^ 2 \
tan ^ 2 theta left ( frac { vec r_h + vec v_h t} t right) ^ 2 & = l_v ^ 2 \
tan ^ 2 theta left ( frac {r_h ^ 2} {t ^ 2} + 2 frac { vec r_h cdot vec v_h} t + v_h ^ 2 right) & = l_v ^ 2
end {align} $$

Now, we want to know if this vertical launch speed will bring us up to our target at the end of the bow at the hour. $ t $:

$$ begin {align}
l_v t – frac g 2 t ^ 2 & = r_v \
l_v & = frac {r_v} t + frac g 2 t \
l_v ^ 2 & = frac {r_v ^ 2} {t ^ 2} + r_v g + frac {g ^ 2} 4 t ^ 2 \
tan ^ 2 theta left ( frac {r_h ^ 2} {t ^ 2} + 2 frac { vec r_h cdot vec v_h} t + v_h ^ 2 right) & = frac {r_v ^ 2} {t ^ 2} + r_v g + frac {g ^ 2} 4 t ^ 2 \
tan ^ 2 theta left (r_h ^ 2 + 2 vec r_h cdot vec v_h t + v_h ^ 2 t ^ 2 right) & = r_v ^ 2 + r_v gt ^ 2 + frac {g ^ 2 } 4 t ^ 4 \
t ^ 4 left ( frac {g ^ 2} 4 right)
+ t ^ 2 left (r_v g – left ( tan theta right) ^ 2 v_h ^ 2 right)
– t left (2 left ( tan theta right) ^ 2 vec r_h cdot vec v_h right)
– left ( tan theta right) ^ 2 r_h ^ 2
& = 0
end {align} $$

We now have a quartic equation in a variable with known real number coefficients. As described in this answer, you can apply your favorite quarter resolution routine (an example in the comments) to search for potential values ​​of $ t $ that satisfy the equation. In general, there could be up to four solutions. We are only looking for those who are …

  • real numbers (imaginary zero component)
  • greater than zero (negative values ​​correspond to shots target could have been lobbying we hit us at our launch angle at time 0)

If you have several candidate solutions that meet these criteria, you can freely choose between them. Generally, the smaller the time value $ t $ the longer the bow is shallow, but also the less the target has time to change course and dodge. Higher $ t $ the solutions generally correspond to larger arcs (we spend more time flying in the air), which leaves more time for the target to escape.

With your chosen time $ t $ in hand, you can substitute it in the equations above to find your horizontal and vertical launch velocity components and combine them into the final velocity.