How this calculation works
Skew lines do not meet and are not parallel, which can occur only in three or more dimensions. Their shortest joining segment is perpendicular to both line directions. This page solves for the two points at the ends of that segment, rather than returning a distance without its location. Parallel, coincident and intersecting configurations are handled separately and labeled in the result. Direction-vector magnitudes do not affect the geometric line.
Minimize |P + s·u − Q − t·v|²; for nonparallel directions, distance = |(Q−P)·(u×v)|/|u×v|.A worked example
Take P = (0,0,0), u = (1,0,0), Q = (0,0,1) and v = (0,1,0). The first line is the x-axis at z = 0; the second follows the y direction at z = 1. The closest points are P and Q themselves, and their separation is one coordinate unit. The lines are skew even though a two-dimensional projection can make them appear to cross.
Good to know
All components must be finite and within ±1,000,000. Zero direction vectors are invalid. Numerically ill-conditioned nearly parallel directions are rejected with an explanation. The calculation uses infinite lines, not finite segments or forward-only rays. A numerical zero-distance tolerance is shown in the steps; no measurement-uncertainty model is inferred.
Reference: OpenStax Calculus — equations of lines and planes in space (opens in a new tab) ↗
The closest pair explains where the distance occurs
Write the first line as P + s·u and the second as Q + t·v. Differentiating their squared separation with respect to s and t gives two orthogonality equations. Solving them locates a closest pair. The table provides those coordinates and the metrics provide the parameters relative to your original, unnormalized direction vectors. Substituting the parameters back into both line equations is an independent check.
For nonparallel lines, the cross-product formula gives the same distance by projecting the offset Q − P onto the common normal u × v. A zero scalar triple product means the nonparallel lines are coplanar and intersect. A nonzero value indicates skew lines. Returning the joining segment as well as this scalar helps distinguish spatial distance from a misleading crossing in a flat drawing.
The vector dot product checks that the joining segment is perpendicular to each nonparallel line direction.
Parallel lines have no unique closest pair
If u × v is zero, dividing by its length is invalid. The calculator instead fixes the second parameter at zero and projects Q onto the first line. Translating both closest points together along the common direction would give another equally good pair. Coincident lines are the special parallel case with zero distance, and the result does not claim a unique intersection point.
Near-parallel directions can force the closest points very far from the entered reference points. Small input changes can then produce large parameter changes even when the directions remain valid. The solver rejects sufficiently ill-conditioned cases rather than presenting unstable coordinates as reliable. A finite-segment distance problem would require clamping parameters to segment bounds and checking endpoints. That is a separate task from the unrestricted infinite lines used here.
A few questions, answered
Must direction vectors be normalized first?
No. Any nonzero multiple describes the same line. The solver normalizes internally and converts the reported parameters back to your entered directions.
Can two nonparallel lines in 3D fail to intersect?
Yes. They are skew when they are not coplanar. Their shortest connecting segment then has positive length.