Consider two lines in space `1 and `2 such that `1 passes through point P1 and is parallel to vector ~v1 and `2 passes through P2 and is parallel to ~v2. We want to compute the smallest distance D between the two lines.
If the two lines intersect, then it is clear that D = 0. If they do not intersect and are parallel, then D corresponds to the distance between point P2 and line `1 and is given by D = kāāāā P1P2 Ć~v1k k~v1k . Assume the lines are not parallel and do not intersect (skew lines) and let ~n = ~v1 Ć~v2 be a vector perpendicular to both lines. The norm of the projection of vector āāāā P1P2 over ~n will give us D, i.e., D = |āāāā P1P2 Ā·~n| k~nk . Example Consider the two lines `1 : x = 0, y =āt, z = t and `2 : x = 1+2s, y = s, z =ā3s. It is easy to see that the two lines are skew. Let P1 = (0,0,0), ~v1 = (0,ā1,1), P2 = (1,0,0), and ~v2 = (2,1,ā3). Then, āāāā P1P2 = (1,0,0) and ~n = ~v1 Ć~v2 = (2,2,2). We then get D = |āāāā P1P2 Ā·~n| k~nk = 1 ā3. Observe that the problem can also by solved with Calculus. Consider the problem of minimizing the Euclidean distance between two points on `1 and `2. Let Q1 = (x1,y1,z1) and Q2 = (x2,y2,z2) be arbitrary points on `1 and `2, and let F(s,t) = (x2 āx1)2 +(y2 āy1)2 +(z2 āz1)2 = (1+2s)2 +(s + t)2 +(ā3sāt)2 = 14s2 +2t2 +8st +4s+1. Note that F(s,t) corresponds to the square of the Euclidean distance between Q1 and Q2. Letās nd the critical points of F. Fs(s,t) = 28s+8t +4 = 0 Ft(s,t) = 4t +8s = 0 By solving the linear system, we nd that the unique critical point is (s0,t0) = (ā1/3,2/3). Since the Hessian matrix of F, H =Fss Fst Fts Ftt=28 8 8 4, is positive denite, the critical point corresponds to the absolute minimum of F over all (s,t)āR2. The minimal distance between the two lines is then D =pF(s0,t0) = 1 ā3.