Suppose we have two objects in a 3D space:
- The first object, A, is at the given position P1 moving at a constant 3D Vector speed of V1
- The second object, B, is at a given position that we will call P2
Knowing that B can only move at a speed of magnitude M1, in which direction should B move in order to touch A? The result must be expressed as a Unit 3D Vector
Here's a visual image I put up in Paint to help visualize the problem: Visual Example
Thank you.
Let the position of the target be a vector-valued function $$\vec{p}(t) = \vec{b} + t \vec{v} \tag{1a}\label{1a}$$ and the position of the interceptor $$\vec{P}(t) = \vec{B} + t \vec{V}, \quad \lVert \vec{V} \rVert = M \tag{1b}\label{1b}$$ so that at some time $\tau \gt 0$, the two collide: $$\vec{p}(\tau) = \vec{P}(\tau) \tag{2}\label{2}$$ Expanding and simplifying $\eqref{2}$ we get $$\begin{aligned} \vec{b} + \tau \vec{v} &= \vec{B} + \tau \vec{V} \\ \tau \vec{V} &= \vec{b} - \vec{B} + \tau \vec{v} \\ \vec{V} &= \vec{v} + \frac{\vec{b} - \vec{B}}{\tau} \\ \end{aligned} \tag{3}\label{3}$$ In Cartesian component form, we have four equations and four unknowns ($V_x$, $V_y$, $V_z$, and $\tau$): $$\left\lbrace ~ \begin{aligned} M^2 &= V_x^2 + V_y^2 + V_z^2 \\ V_x &= v_x + \frac{b_x - B_x}{\tau} \\ V_y &= v_y + \frac{b_y - B_y}{\tau} \\ V_z &= v_z + \frac{b_z - B_z}{\tau} \\ \end{aligned} \right. \tag{4a}\label{4a}$$ This can have zero, one, or two sets of real solutions: $$\begin{cases} \tau = \frac{\vec{v} \cdot (\vec{B} - \vec{b})}{\lVert\vec{v}\rVert^2 - M^2} \pm \frac{\sqrt{ M^2 \lVert \vec{B} - \vec{b} \rVert^2 - \lVert \vec{v}\times(\vec{B} - \vec{b})\rVert^2}}{\lVert \vec{v} \rVert^2 - M^2}, & \lVert\vec{v}\rVert \ne M \\ \tau = \frac{\lVert \vec{B} - \vec{b} \rVert^2}{2 \vec{v} \cdot (\vec{B} - \vec{b}) }, & \lVert\vec{v}\rVert = M \\ \end{cases} \tag{4b}\label{4b}$$ where only $\tau \gt 0$ makes sense. Note that the second only has a positive real solution when $\vec{v}$ is (in the half-space) towards $\vec{B}$ from $\vec{b}$. Then, $$\vec{V} = \frac{\vec{v} + \vec{b} - \vec{B}}{M \tau} \tag{4c}\label{4c}$$ and $\lVert\vec{V}\rVert = 1$ within rounding error.
You can obtain these using Maxima or wxMaxima (free, available for all operating systems) or some other Computer Algebra System like Maple, via e.g.
Here is an example Python 3 implementation of the above:
When run, the above generates a random origin, random target, random target velocity, random interceptor speed, and finds the interceptor direction.