In a plane, given—
- a target $T$ at position $(x_{0}, y_{0})$ with initial velocity $(v_{x}, v_{y})$ and fixed acceleration $(a_{xT}, a_{yT})$, and
- an interceptor $i$ initially at rest at position $(0, 0)$ with fixed acceleration (magnitude) $a_{I}$
—how do I find the angle (or the components $(a_{xI}, a_{yI})$ into which to decompose the acceleration vector) at which $I$ should accelerate, in order to intercept $T$ in minimum time?
We can calculate the positions (in that reference frame) of target and interceptor at time $t$ as:
$$x_{tT}=x_{0}+v_{x}t+\frac{1}{2}a_{xT}t^{2}$$
$$y_{tT}=y_{0}+v_{y}t+\frac{1}{2}a_{yT}t^{2}$$
$$x_{tI}=\frac{1}{2}a_{xI}t^{2}$$
$$y_{tI}=\frac{1}{2}a_{yI}t^{2}$$
At interception, $(x_{tT},y_{tT})=(x_{tI},y_{tI})$, giving us the identities:
$$\frac{1}{2}a_{xI}t^{2}=x_{0}+v_{x}t+\frac{1}{2}a_{xT}t^{2}$$
$$\frac{1}{2}a_{yI}t^{2}=y_{0}+v_{y}t+\frac{1}{2}a_{yT}t^{2}$$
It seems like we should therefore be able to solve this with the quadratic formula:
$$(a_{xI}-a_{xT})t^{2}-2v_{x}t-2x_{0}=0$$
$$(a_{yI}-a_{yT})t^{2}-2v_{y}t-2y_{0}=0$$
$$[(a_{xI}-a_{xT})-(a_{yI}-a_{yT})]t^{2}-2(v_{x}+v_{y})t-2(x_{0}+y_{0})=0$$
$$t=\frac{(v_{x}+v_{y})\pm\sqrt{(v_{x}+v_{y})^{2}-2[(a_{xI}-a_{xT})-(a_{yI}-a_{yT})](x_{0}+y_{0})}}{(a_{xI}-a_{xT})-(a_{yI}-a_{yT})}$$
But I'm up to four pages of LaTeX with no end in sight and a lot of opportunities to accidentally flip a sign or drop a factor of two or accidentally take the root of a negative or divide by zero.
It seems like there must be a better way.
Notes:
- this comment hints at a solution, but doesn't give it.
- this answer gives a general method, similar to the above, noting that $a_{xI}=a_{I} cos \theta$ and $a_{yI}=a_{I} sin \theta$, but just says “now you need to solve these equations, by eliminating $t$” which I think is what I’m stuck on, or at least mired in.
Here’s one approach to finding a solution, although it involves solving a quartic equation, so I’m not sure how feasible it will be in practice.
Let $\mathbf r_0$, $\mathbf v_0$ and $\mathbf a_T$ be the target’s initial position, velocity and (constant) acceleration. The path of the target is the (possibly degenerate) parabola $\mathbf r: t\mapsto\mathbf r_0+\mathbf v_0t+\frac12\mathbf a_Tt^2$ and its distance from the origin at time $t$ is $\|\mathbf r(t)\|$. The interceptor travels in a straight line from the origin and the distance it covers in time $t$ is $\frac12a_It^2$, so you’re looking for the least $t\ge0$ such that $\|\mathbf r(t)\|=\frac12a_It^2$. Squaring both sides and expanding produces the equation $$\frac14(\|\mathbf a_T\|^2-a_I^2)\,t^4+(\mathbf a_T\cdot\mathbf v_0)\,t^3+(\|\mathbf v_0\|^2+\mathbf a_T\cdot\mathbf r_0)\,t^2+2(\mathbf v_0\cdot\mathbf r_0)\,t+\|\mathbf r_0\|^2=0.\tag{*}$$ Once you have a solution (if there is one), plug it back into $\mathbf r(t)$ and normalize to get the launch vector of the interceptor.
Update: From the linked questions, it looks like this calculation is part of a video game. For the purposes of that game, an approximation to the true solution is likely good enough. A simple way to compute such an approximation is to run the target’s position forward in time. You’re probably quantizing time in “ticks,” so compute successive values of the difference in the two distances mentioned above (or the squares of those distances, which might be more efficient to compute). When this difference changes sign, you know that the first intercept time is somewhere between that tick and the previous one. Interpolate the target’s position between these two ticks and set the interceptor launch vector accordingly. This is essentially a graphical solution to the problem. With this method, you can easily include things like a cutoff that represents a maximum range for the missile.
This approach could fail to find a solution if the target can make a radical direction change within a single tick. If that’s a possibility, and even if it isn’t, you might also want to check for when the difference changes from decreasing to increasing with successive ticks. If that happens sufficiently close to zero, then you’re likely to be near a practical solution—you could even have a “blast radius” so that near-misses are good enough. Otherwise, you’ll need to keep searching for a zero crossing.
Various methods exist for getting a quick estimate on the bounds of the roots of equation (*), which you can use to limit this search. Look here for some possibilities for further research. For instance, Descarte’s rule of signs gives you a very fast upper bound on the number of positive roots, and for a quartic you can usually characterize all of the roots.