[Math] Find shortest distance between lines in 3D

3dgeometryvectors

Find shortest distance between lines given by

$$\frac{x-2}{3}=\frac{y-6}{4}=\frac{z+9}{-4}$$
and
$$\frac{x+1}{2}=\frac{y+2}{-6}=\frac{z-3}{1}$$
Is there any shortcut method for this problems?

Best Answer

So you have two lines defined by the points $\mathbf{r}_1=(2,6,-9)$ and $\mathbf{r}_2=(-1,-2,3)$ and the (non unit) direction vectors $\mathbf{e}_1=(3,4,-4)$ and $\mathbf{e}_2 =(2,-6,1)$.

The coordinates of all the points along the lines are given by

$$\begin{align} \mathbf{p}_1 & = \mathbf{r}_1 + t_1 \mathbf{e}_1 \\ \mathbf{p}_2 & = \mathbf{r}_2 + t_2 \mathbf{e}_2 \\ \end{align}$$

where $t_1$ and $t_2$ are two scalar values. To find the closest points along the lines you recognize that the line connecting the closest points has direction vector $$\mathbf{n} = \mathbf{e}_1 \times \mathbf{e}_2 = (-20,-11,-26)$$

If the two direction vectors $\mathbf{e}_1$ and $\mathbf{e}_2$ are parallel (not in this specific case), this method cannot be applied because the cross product is zero:

$$\mathbf{e}_1 \times \mathbf{e}_2 = 0$$

If the points along the two lines are projected onto the cross line the distance is found with one fell swoop

$$ d = \frac{ \mathbf{n}\cdot \mathbf{p}_1}{\|\mathbf{n}\|} - \frac{ \mathbf{n}\cdot \mathbf{p}_2}{\|\mathbf{n}\|} = \frac{ \mathbf{n} \cdot ( \mathbf{p}_1-\mathbf{p}_2)}{\| \mathbf{n} \|} = \frac{ \mathbf{n} \cdot ( \mathbf{r}_1-\mathbf{r}_2+t_1 \mathbf{e}_1 -t_2 \mathbf{e}_2)}{\| \mathbf{n} \|} $$

But since $\mathbf{n}\cdot \mathbf{e}_1 = \mathbf{n}\cdot \mathbf{e}_2 = 0$, the above is

$$ \boxed{ d = \frac{ \mathbf{n} \cdot ( \mathbf{r}_1-\mathbf{r}_2)}{\| \mathbf{n} \|} }$$

In this case $$ d = \frac{ (-20,-11,-26) \cdot (3,8,-12) }{3 \sqrt{133}} = 4.74020116673185 $$