# Find third 3d coordinate given two other coordinates

Given the 3d coordinates of the 2 spheres (see image below) and the length of the Box, how can find the 3d coordinates at the end of the box using an equation?

-
What are the conditions on the shapes? Is it that the box is tangent to the green sphere, and the long edge of the box is parallel to the line between the two spheres? – Lopsy Feb 11 '12 at 15:44
the box and 2 spheres are on a straight line – Nipuna Feb 11 '12 at 15:55

If the coordinates of the center of the blue sphere are $B=(B_x,B_y,B_z)$ and the coordinates of the center of the green sphere are $G=(G_x,G_y,G_z)$, then the vector $$\overrightarrow{BG}=G-B=\langle G_x-B_x,G_y-B_y,G_z-B_z\rangle$$ and we can unitize that vector (create a vector of length 1 in the same direction by taking $$\vec{n}=\frac{\overrightarrow{BG}}{\|\overrightarrow{BG}\|}=\left\langle\frac{G_x-B_x}{\|\overrightarrow{BG}\|},\frac{G_y-B_y}{\|\overrightarrow{BG}\|},\frac{G_z-B_z}{\|\overrightarrow{BG}\|}\right\rangle$$ where $\|\overrightarrow{BG}\|=\sqrt{(G_x-B_x)^2+(G_y-B_y)^2+(G_z-B_z)^2}$.
Now, the distance from the center of the green sphere to the middle of the far end of the box is the length of the box plus the radius of the sphere. Let's call that total distance $d$. The vector $d\vec{n}$ will have length $d$ and be in the same direction as the vector from B to G, which is along the line through the centers of the spheres. If we add $d\vec{n}$ to $G$, we'll get the coordinates of the center of the far end of the box: \begin{align} G+d\vec{n} &=(G_x,G_y,G_z)+d\left\langle\frac{G_x-B_x}{\|\overrightarrow{BG}\|},\frac{G_y-B_y}{\|\overrightarrow{BG}\|},\frac{G_z-B_z}{\|\overrightarrow{BG}\|}\right\rangle \\ &=\left\langle G_x+d\cdot\frac{G_x-B_x}{\|\overrightarrow{BG}\|},G_y+d\cdot\frac{G_y-B_y}{\|\overrightarrow{BG}\|},G_z+d\cdot\frac{G_z-B_z}{\|\overrightarrow{BG}\|}\right\rangle. \end{align}