Math Lab
Home/Class XII/Ch 11/Shortest distance between two lines

Shortest distance between two lines

Two lines in 3D may be skew , neither parallel nor intersecting. The shortest distance between them is the length of the common perpendicular: the unique line segment that meets both lines at right angles.

The skew-line formula

Let line 1 be r=a1+td1\vec r = \vec a_1 + t \vec d_1 and line 2 be r=a2+sd2\vec r = \vec a_2 + s \vec d_2, with d1∦d2\vec d_1 \not\parallel \vec d_2.

A vector perpendicular to both directions is d1×d2\vec d_1 \times \vec d_2. Its unit version is n^=d1×d2d1×d2\hat n = \dfrac{\vec d_1\times\vec d_2}{|\vec d_1\times\vec d_2|}.

The shortest distance is the absolute value of the projection of the displacement a2a1\vec a_2 - \vec a_1 onto n^\hat n: D=(a2a1)(d1×d2)d1×d2.D = \left|\frac{(\vec a_2 - \vec a_1)\cdot (\vec d_1 \times \vec d_2)}{|\vec d_1 \times \vec d_2|}\right|.

The numerator is the signed triple product; the absolute value gives the geometric distance.

Why does this work?

The common perpendicular has direction d1×d2\vec d_1 \times \vec d_2. To find how "far apart" the lines are along this perpendicular direction, project the line-to-line displacement a2a1\vec a_2 - \vec a_1 onto n^\hat n. The result is the gap.

Parallel lines

If d1d2\vec d_1 \parallel \vec d_2, the formula above breaks down (the cross product is zero). For two parallel lines, every perpendicular to one is perpendicular to the other; the distance is just the perpendicular distance from any point of line 2 to line 1: D=(a2a1)×d1d1.D = \frac{|(\vec a_2 - \vec a_1)\times \vec d_1|}{|\vec d_1|}.

Cartesian version

Lines xx1a1=yy1b1=zz1c1\dfrac{x - x_1}{a_1} = \dfrac{y - y_1}{b_1} = \dfrac{z - z_1}{c_1} and xx2a2=yy2b2=zz2c2\dfrac{x - x_2}{a_2} = \dfrac{y - y_2}{b_2} = \dfrac{z - z_2}{c_2} have shortest distance D=det(x2x1y2y1z2z1a1b1c1a2b2c2)(b1c2b2c1)2+(c1a2c2a1)2+(a1b2a2b1)2.D = \frac{\left|\det\begin{pmatrix} x_2 - x_1 & y_2 - y_1 & z_2 - z_1 \\ a_1 & b_1 & c_1 \\ a_2 & b_2 & c_2\end{pmatrix}\right|}{\sqrt{(b_1 c_2 - b_2 c_1)^2 + (c_1 a_2 - c_2 a_1)^2 + (a_1 b_2 - a_2 b_1)^2}}.

(The numerator is the triple product written componentwise; the denominator is d1×d2|\vec d_1 \times \vec d_2|.)

Intersecting check

Distance =0    = 0 \iff the two lines intersect. So computing this number doubles as a test: zero means they meet, non-zero means they don't.

Worked examples

Example 1. Find the shortest distance between r=i^+2j^+3k^+t(i^+j^+k^)\vec r = \hat i + 2\hat j + 3\hat k + t(\hat i + \hat j + \hat k) and r=2i^+3j^+4k^+s(2i^j^+k^)\vec r = 2\hat i + 3\hat j + 4\hat k + s(2\hat i - \hat j + \hat k).

a1=(1,2,3)\vec a_1 = (1, 2, 3), d1=(1,1,1)\vec d_1 = (1, 1, 1). a2=(2,3,4)\vec a_2 = (2, 3, 4), d2=(2,1,1)\vec d_2 = (2, -1, 1).

d1×d2=i^j^k^111211=i^(1+1)j^(12)+k^(12)=2i^+j^3k^\vec d_1\times\vec d_2 = \begin{vmatrix}\hat i & \hat j & \hat k\\1 & 1 & 1\\2 & -1 & 1\end{vmatrix} = \hat i(1 + 1) - \hat j(1 - 2) + \hat k(-1 - 2) = 2\hat i + \hat j - 3\hat k. Magnitude 4+1+9=14\sqrt{4 + 1 + 9} = \sqrt{14}.

a2a1=(1,1,1)\vec a_2 - \vec a_1 = (1, 1, 1). Dot with cross: 2+13=02 + 1 - 3 = 0.

Distance =0/14=0= 0/\sqrt{14} = 0. Lines intersect.

Example 2. Find the shortest distance between lines x12=y23=z34\dfrac{x - 1}{2} = \dfrac{y - 2}{3} = \dfrac{z - 3}{4} and x23=y34=z55\dfrac{x - 2}{3} = \dfrac{y - 3}{4} = \dfrac{z - 5}{5}.

a1=(1,2,3)\vec a_1 = (1, 2, 3), d1=(2,3,4)\vec d_1 = (2, 3, 4). a2=(2,3,5)\vec a_2 = (2, 3, 5), d2=(3,4,5)\vec d_2 = (3, 4, 5). a2a1=(1,1,2)\vec a_2 - \vec a_1 = (1, 1, 2).

d1×d2=i^j^k^234345=i^(1516)j^(1012)+k^(89)=i^+2j^k^\vec d_1\times\vec d_2 = \begin{vmatrix}\hat i & \hat j & \hat k\\2 & 3 & 4\\3 & 4 & 5\end{vmatrix} = \hat i(15 - 16) - \hat j(10 - 12) + \hat k(8 - 9) = -\hat i + 2\hat j - \hat k. Magnitude 1+4+1=6\sqrt{1 + 4 + 1} = \sqrt 6.

(a2a1)(d1×d2)=(1)(1)+(1)(2)+(2)(1)=1(\vec a_2 - \vec a_1)\cdot(\vec d_1\times\vec d_2) = (1)(-1) + (1)(2) + (2)(-1) = -1. Absolute value: 11.

Distance =1/6= 1/\sqrt 6.

Example 3. Show that the lines x+13=y+35=z+57\dfrac{x + 1}{3} = \dfrac{y + 3}{5} = \dfrac{z + 5}{7} and x21=y43=z65\dfrac{x - 2}{1} = \dfrac{y - 4}{3} = \dfrac{z - 6}{5} are coplanar.

a2a1=(3,7,11)\vec a_2 - \vec a_1 = (3, 7, 11). d1=(3,5,7)\vec d_1 = (3, 5, 7), d2=(1,3,5)\vec d_2 = (1, 3, 5).

Triple product: det(3711357135)=3(2521)7(157)+11(95)=1256+44=0\det \begin{pmatrix} 3 & 7 & 11 \\ 3 & 5 & 7 \\ 1 & 3 & 5\end{pmatrix} = 3(25 - 21) - 7(15 - 7) + 11(9 - 5) = 12 - 56 + 44 = 0.

Triple product zero, so coplanar.

Example 4. Find the distance between the two parallel lines r=i^+j^+t(2i^j^+k^)\vec r = \hat i + \hat j + t(2\hat i - \hat j + \hat k) and r=2i^j^+s(2i^j^+k^)\vec r = 2\hat i - \hat j + s(2\hat i - \hat j + \hat k).

Parallel direction d=(2,1,1)\vec d = (2, -1, 1), d=6|\vec d| = \sqrt 6. a2a1=(1,2,0)\vec a_2 - \vec a_1 = (1, -2, 0). (a2a1)×d=i^j^k^120211=i^(20)j^(10)+k^(1+4)=2i^j^+3k^(\vec a_2 - \vec a_1)\times\vec d = \begin{vmatrix}\hat i & \hat j & \hat k\\1 & -2 & 0\\2 & -1 & 1\end{vmatrix} = \hat i(-2 - 0) - \hat j(1 - 0) + \hat k(-1 + 4) = -2\hat i - \hat j + 3\hat k. Magnitude 4+1+9=14\sqrt{4 + 1 + 9} = \sqrt{14}.

Distance =14/6=14/6=7/3= \sqrt{14}/\sqrt 6 = \sqrt{14/6} = \sqrt{7/3}.

Example 5. Find the shortest distance between r=(1,2,3)+t(1,0,0)\vec r = (1, 2, 3) + t(1, 0, 0) and r=(0,0,0)+s(0,0,1)\vec r = (0, 0, 0) + s(0, 0, 1).

d1=(1,0,0)\vec d_1 = (1, 0, 0), d2=(0,0,1)\vec d_2 = (0, 0, 1). d1×d2=(0,1,0)\vec d_1\times\vec d_2 = (0, -1, 0), magnitude 11. a2a1=(1,2,3)\vec a_2 - \vec a_1 = (-1, -2, -3). Dot with cross: (1)(0)+(2)(1)+(3)(0)=2(-1)(0) + (-2)(-1) + (-3)(0) = 2. Distance =2= 2. (Note: this is the yy-coordinate difference, since the lines are the xx-axis-parallel line at y=2,z=3y = 2, z = 3 and the zz-axis. Closest approach has y=2y = 2 in line 1 and y=0y = 0 in line 2, so the gap in yy alone is 2.)

Example 6. Determine whether the lines x1=y2=z3\dfrac{x}{1} = \dfrac{y}{2} = \dfrac{z}{3} and x21=y42=z63\dfrac{x - 2}{1} = \dfrac{y - 4}{2} = \dfrac{z - 6}{3} are coincident, parallel, or skew.

Same direction (1,2,3)(1, 2, 3). Try the point (2,4,6)(2, 4, 6) on the second line: does it lie on the first? 21=42=63=2\dfrac{2}{1} = \dfrac{4}{2} = \dfrac{6}{3} = 2. Yes , coincident.

Try it yourself

  1. Shortest distance between r=(1,0,0)+t(0,0,1)\vec r = (1, 0, 0) + t(0, 0, 1) and r=(0,1,0)+s(1,0,0)\vec r = (0, 1, 0) + s(1, 0, 0).
  2. Shortest distance between x11=y22=z33\dfrac{x - 1}{1} = \dfrac{y - 2}{2} = \dfrac{z - 3}{3} and x21=y32=z43\dfrac{x - 2}{1} = \dfrac{y - 3}{2} = \dfrac{z - 4}{3} , note they may be parallel or coincident.
  3. Find the shortest distance between r=(3,5,7)+t(1,2,1)\vec r = (3, 5, 7) + t(1, -2, 1) and r=(1,1,1)+s(7,6,1)\vec r = (-1, -1, -1) + s(7, -6, 1).
  4. Show that lines x+21=y12=z53\dfrac{x + 2}{1} = \dfrac{y - 1}{2} = \dfrac{z - 5}{3} and x+12=y4=z+16\dfrac{x + 1}{2} = \dfrac{y}{4} = \dfrac{z + 1}{6} are coplanar.
  5. Find the shortest distance between two parallel lines x12=y+13=z1\dfrac{x - 1}{2} = \dfrac{y + 1}{3} = \dfrac{z}{1} and x42=y3=z11\dfrac{x - 4}{2} = \dfrac{y}{3} = \dfrac{z - 1}{1}.
  6. Find the line that is the common perpendicular of r=(0,0,0)+t(1,0,0)\vec r = (0, 0, 0) + t(1, 0, 0) and r=(0,0,1)+s(0,1,0)\vec r = (0, 0, 1) + s(0, 1, 0).
  7. For what values of λ\lambda are the lines x12=y+13=z14\dfrac{x - 1}{2} = \dfrac{y + 1}{3} = \dfrac{z - 1}{4} and x31=yλ2=z1\dfrac{x - 3}{1} = \dfrac{y - \lambda}{2} = \dfrac{z}{1} coplanar?
  8. Determine if r=(1,2,3)+t(2,0,1)\vec r = (1, 2, 3) + t(2, 0, 1) and r=(2,4,6)+s(1,1,0)\vec r = (2, 4, 6) + s(1, 1, 0) intersect.
  9. Find the perpendicular distance from origin to x11=y1=z1\dfrac{x - 1}{1} = \dfrac{y}{1} = \dfrac{z}{1}.
  10. Lines L1:r=td1L_1: \vec r = t\vec d_1 and L2:r=b+sd2L_2: \vec r = \vec b + s\vec d_2 both pass through origin (if b=0\vec b = \vec 0) , find shortest distance for b=(1,1,1)\vec b = (1, 1, 1), d1=(1,0,0)\vec d_1 = (1, 0, 0), d2=(0,1,0)\vec d_2 = (0, 1, 0).
  11. Find shortest distance between xx-axis and r=(1,1,1)+t(0,0,1)\vec r = (1, 1, 1) + t(0, 0, 1).
  12. The two diagonals of opposite faces of a unit cube , find the distance between them.
  13. Find the foot of the common perpendicular from (0,0,0)(0, 0, 0) on the line through (1,1,1)(1, 1, 1) with direction (1,1,1)(1, 1, 1).
  14. Two skew edges of a regular tetrahedron with side 11 , find the shortest distance between them.

Pitfalls and tricks

  • Test parallelism first before applying the skew formula , division by zero awaits.
  • Triple product zero \Leftrightarrow coplanar lines (intersect or parallel).
  • Absolute value outside the entire expression , the unsigned distance is what you want.
  • For parallel lines use the cross-product formula (a2a1)×d/d|(\vec a_2 - \vec a_1)\times\vec d|/|\vec d|.
  • Sketch when possible. Even a sketch of one line plus a perpendicular helps verify the geometry.

Practice quiz

Quick check on this topic.

Quiz
Quick check : Shortest distance
6 questions · pick the best answer
Q1

Shortest distance formula uses

Q2

If distance is 0, the lines

Q3

For parallel lines, use formula

Q4

Lines coplanar iff triple product

Q5

Direction of common perpendicular of two skew lines

Q6

Numerator in shortest-distance formula uses