# Minimum distance of intersection between two spheres along a specified vector

I have two spheres $$(S_1, S_2)$$ within a Cartesian space defined by their centroids $$(p_1,p_2)$$ and their radii $$(r_1,r_2)$$. $$p_1$$ is located at the origin of the coordinate frame such that $$x_1^2 + y_1^2 + z_1^2 = r_1^2$$. $$p_2$$ is located at the point $$(x_0, y_0, z_0)$$ such that $$(x_2 - x_0)^2 + (y_2 - y_0)^2 + (z_2 - z_0)^2 = r_2^2$$. $$S_2$$ lies in the path of $$S_1$$ as it is translated along the unit vector $$V$$ $$=$$ $$[0$$ $$0$$ $$-1]$$. Note that the centroids of the spheres are not coincident along the vector $$V$$ (see the attached figure), otherwise the solution would be trivial.

I am trying to determine the translation $$p_1 - t$$ at which $$S_1$$ will 'collide' (i.e. intersect) with $$S_2$$ (see the linked image). I am happy to use a solution that assumes that $$V$$ is aligned to the coordinate axis (i.e. my example above) rather than any arbitrary vector. I know that the equivalent problem in two dimensions can be solved as follows

$$d = \min(p_y \pm \sqrt{(r_1+r_2)^2 - p_x^2})$$, where $$p_x = x_1 - x_0$$, $$p_y = y_1 - y_0$$ and $$d$$ is the minimum distance along $$V$$ that $$S_1$$ intersects with $$S_2$$

Any help would be greatly appreciated!

• Find the point where the distances between the two centers is $r_1 + r_2$. Commented Jul 18, 2020 at 15:08

Parametrize the center of the second sphere along the translation vector as $$t$$, for example $$\vec{c} = \vec{c}_0 + t \vec{c}_V$$ and solve for $$t$$ in $$\lVert \vec{c} \rVert = r_1 + r_2$$ Typically, it is easier to solve for the squared distance, i.e. $$\lVert \vec{c} \rVert^2 = \left(r_1 + r_2\right)^2$$ which is allowed because both sides are nonnegative anyway.
If we assume $$\vec{c}_0 = (x_0 , y_0 , z_0)$$ and $$\vec{c}_V = (0, 0, 1)$$, then $$\lVert \vec{c} \rVert^2 = x_0^2 + y_0^2 + (z_0 + t)^2$$ and therefore \begin{aligned} x_0^2 + y_0^2 + (z_0 + t)^2 &= (r_1 + r_2)^2 \\ t^2 + 2 z_0 t + x_0^2 + y_0^2 - (r_1 + r_2)^2 &= 0 \\ t &= - z_0 \pm \sqrt{ (r_1 + r_2)^2 - x_0^2 - y_0^2 } \\ \end{aligned}