Use parametric equations for the two lines,
Their cross product is . Projection of the separation of the base points onto this common normal gives the shortest distance between skew lines:
This projection is a lower bound on every connecting segment because adding either line's direction leaves its normal component unchanged. It is attained: imposing perpendicularity of to both directions gives and . The corresponding points are and ; their difference is , perpendicular to both lines and of length .
For nonparallel lines, is perpendicular to both direction vectors. Every displacement between the lines differs from by a vector in their span, so its component along is fixed. Varying the two parameters cancels the component in that span. The shortest distance between skew lines is therefore
This also gives zero for intersecting nonparallel lines. For parallel lines the denominator vanishes and the correct separate formula is .
The given lines have vector forms
Here and . Their scalar triple product is , giving
As a constructive check, the closest parameters are and , where the connecting vector is and is perpendicular to both lines.