Find initial vector for shell so that it hits desired target

273 Views Asked by At

Backstory:

  • We are shooting a cannon from a moving platform (e.g., a ship). Platform velocity is $p$.
  • We know where our target is in relation to us (vector $t$)
  • We know the velocity of our shell ($|s|$)
  • We are in possession of ballistics tables that for a given gun angle and shell velocity specify how far the shell is supposed to reach (and we are very quick in searching them so we have a function $f$ that returns angle $\alpha$ such as to hit a certain distance, assuming certain shell speed)
  • The shell is relatively slow-moving so the platform velocity significantly affects aim, we cannot ignore it
  • We assume the target stays still
  • We want to find out where to aim our cannon so that we hit the target

Variables:

  • $s$ - initial vector for shell
  • $p$ - platform vector for the platform that the shell is launched from ($p_y=0$)
  • $t$ - vector to target ($t_y=0$, as we assume both are on the ground)
  • $r$ - resulting vector for shell ($r = p+s$)

All vectors are 3D unless otherwise stated.

We are given:

  • $|s|$ - initial shell velocity
  • $p$ - platform vector
  • $t$ - vector to target
  • Function $f(|r|, d) = \alpha$ which for a given initial vector magnitude $|r|$ and distance $d$ we want to hit returns the angle $\alpha$ that hits the target

What we want to find:

  • $s$ - initial shell vector

Other notes:

  • Projection of $r$ onto the $xz$ plane is colinear with t (the resulting vector has to go in the direction of the target for us to hit it)

P.S. Seems simple enough, and I have been trying to solve this for a while, mainly by trying to reduce it to a 2D task by projecting it onto the plane where $r$ and $t$ vectors both lie but my vector math/geometry is too rusty.

1

There are 1 best solutions below

0
On

As long as $f$ is a black box, I guess you'll have to optimize this iteratively:

  1. Compute $d$ from $t$
  2. Start with a reasonable guess for $\alpha$
  3. Compute $s$ from $\lvert s\rvert$ and $\alpha$, using the heading from $t$
  4. Compute $r$ from $s$ (and $p$)
  5. Compute $\alpha$ from $r$ and $d$
  6. Use the change in $\alpha$ for next iteration, starting at step 3

It might be that you can directly feed the computed $\alpha$ back into the loop. But at least for some functions $f$ that fixpoint iteration might diverge, and you might have to use e.g. bisection to actually locate the best value of $\alpha$.

If you have more details on $f$, you can improve things. If you can differentiate $f$, then you can do some optimization techniques based on gradient descent.