How to find shortest distance between two skew lines in 3D?
Solution 1:
Per this wikipedia article, if your lines are $\vec{X}=\vec{X_1}+t\vec{D_1}$ and $\vec{X}=\vec{X_2}+t\vec{D_2}$, the distance between them is $$\left|\frac{\vec{D_1}\times\vec{D_2}}{|\vec{D_1}\times\vec{D_2}|}\cdot(\vec{X_1}-\vec{X_2})\right|.$$
Solution 2:
Say you have two lines $\vec L_1 = \vec X_1 + t\vec D_1$ and $\vec L_2 = \vec X_2 + t\vec D_2$.
Start with $(\vec X_1 - \vec X_2)$, which is a skew (non-perpendicular) segment from one line to the other. The distance from $\vec L_1$ to $\vec L_2$ is the component of $(\vec X_1 - \vec X_2)$ that is perpendicular to the lines $\vec L_1$ and $\vec L_2$. We can find this direction by taking the cross product $(\vec L_1 \times \vec L_2)$. After normalizing by dividing by the norm $|\vec L_1 \times \vec L_2|$, take the dot product with $(\vec X_1 - \vec X_2)$ to find the length of the component.
The distance is therefore $$ \left|\frac{\vec{D_1}\times\vec{D_2}}{|\vec{D_1}\times\vec{D_2}|}\cdot(\vec{X_1}-\vec{X_2})\right| = \frac{\left|(\vec{D_1}\times\vec{D_2})\cdot(\vec{X_1}-\vec{X_2})\right|}{|\vec{D_1}\times\vec{D_2}|}. $$
Solution 3:
This is the best (quickest and most intuitive) method I've found so far:
Quick method to find line of shortest distance for skew lines
The idea is to consider the vector linking the two lines ($r, s$) in their generic points and then force the perpendicularity with both lines. (Call the line of shortest distance $t$)
This solution allows us to quickly get three results: The equation of the line of shortest distance between the two skew lines; the intersection point between t and s; the intersection point between t and r.