Shortest distance between two lines

Two straight lines drawn on a flat sheet of paper either meet or run parallel forever — there is no third option. Lift the same idea into three dimensions and a new possibility appears: two lines that never meet and are not parallel either, passing each other like two threads at different heights inside a box. These are called skew lines, and even though they never touch, there is always a well-defined "closest they ever get" — a single shortest distance between them, measured along the one line segment that is perpendicular to both at once. This article builds the general formula for that shortest distance, valid for both the skew case and the parallel case, using the vector cross product and scalar triple product already familiar from Vector Algebra. It closes the Three-Dimensional Geometry chapter of CBSE Class 12: given the equations of two lines, a student should be able to say whether they intersect, are parallel, or are skew, and — for the last two cases — compute exactly how far apart they are.

The core insight

The shortest distance between two skew lines is the length of their common perpendicular, computed as the scalar triple product of the separation vector and the two direction vectors, divided by the magnitude of the cross product of those directions.

The core idea

Take two lines in vector form, r⃗=a1⃗+λb1⃗\vec r = \vec{a_1} + \lambda \vec{b_1} and r⃗=a2⃗+μb2⃗\vec r = \vec{a_2} + \mu \vec{b_2}, where a1⃗,a2⃗\vec{a_1}, \vec{a_2} locate one point on each line and b1⃗,b2⃗\vec{b_1}, \vec{b_2} are their direction vectors. Comparing the two lines always lands in exactly one of three cases: they intersect, they are parallel, or they are skew.

Case 1 — skew or otherwise non-parallel lines. Whenever b1⃗\vec{b_1} and b2⃗\vec{b_2} are not parallel, b1⃗×b2⃗\vec{b_1}\times\vec{b_2} is a nonzero vector perpendicular to both lines — the direction of the common perpendicular. Dotting it with a2⃗−a1⃗\vec{a_2}-\vec{a_1}, the vector joining a point on line 1 to a point on line 2, projects that separation onto this common-perpendicular direction, giving the shortest distance directly:

d=∣(a2⃗−a1⃗)⋅(b1⃗×b2⃗)∣b1⃗×b2⃗∣∣d = \left|\frac{(\vec{a_2}-\vec{a_1})\cdot(\vec{b_1}\times\vec{b_2})}{|\vec{b_1}\times\vec{b_2}|}\right|

where: dd is the shortest distance, a2⃗−a1⃗\vec{a_2}-\vec{a_1} is the vector between the two given points, and b1⃗×b2⃗\vec{b_1}\times\vec{b_2} is the cross product of the two direction vectors. The numerator, (a2⃗−a1⃗)⋅(b1⃗×b2⃗)(\vec{a_2}-\vec{a_1})\cdot(\vec{b_1}\times\vec{b_2}), is a scalar triple product, and the modulus bars around the whole fraction guarantee the answer is a non-negative length regardless of the sign the triple product happens to produce.

Case 2 — parallel lines. If b1⃗\vec{b_1} and b2⃗\vec{b_2} point along the same (or exactly opposite) direction, then b1⃗×b2⃗=0⃗\vec{b_1}\times\vec{b_2}=\vec 0 and Case 1's formula divides by zero. Parallel lines never converge to a common perpendicular pinned by a cross product in that way; instead the distance is the length of the component of a2⃗−a1⃗\vec{a_2}-\vec{a_1} perpendicular to the common direction b⃗\vec b:

d=∣b⃗×(a2⃗−a1⃗)∣b⃗∣∣d = \left|\frac{\vec b \times (\vec{a_2}-\vec{a_1})}{|\vec b|}\right|

where: b⃗\vec b is the common direction of both lines (either b1⃗\vec{b_1} or b2⃗\vec{b_2}, since they are parallel), and the rest of the notation matches Case 1.

Reading d=0d=0. If the Case-1 formula evaluates to d=0d=0, the numerator scalar triple product is zero, which means a2⃗−a1⃗\vec{a_2}-\vec{a_1}, b1⃗\vec{b_1} and b2⃗\vec{b_2} are coplanar. Combined with the lines not being parallel, this forces them to actually meet at a point — the lines intersect. In Cartesian form, with points (x1,y1,z1)(x_1,y_1,z_1), (x2,y2,z2)(x_2,y_2,z_2) and direction ratios (a1,b1,c1)(a_1,b_1,c_1), (a2,b2,c2)(a_2,b_2,c_2), the Case-1 formula becomes a ratio of a 3×33\times3 determinant to the same cross-product magnitude:

d=∣∣x2−x1y2−y1z2−z1a1b1c1a2b2c2∣∣b1⃗×b2⃗∣∣d = \left|\frac{\begin{vmatrix} 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{vmatrix}}{|\vec{b_1}\times\vec{b_2}|}\right|
Figure
Two skew line segments in a three dimensional box connected by a short common perpendicular segment labelled d
Shortest distance between two skew lines line 1 line 2 d The segment d is perpendicular to both lines and has the least possible length among all connecting segments
Derivation AShortest distance between skew lines

The goal is to compute, from the vector equations of two skew lines, the single number that represents how far apart they get at their closest approach — this is the calculation a CBSE board question most commonly asks, so the sequence below should become automatic: identify the four vectors, form the separation, cross the two directions, dot and divide.

Step 1. Write both lines in the form r⃗=a1⃗+λb1⃗\vec r = \vec{a_1}+\lambda\vec{b_1} and r⃗=a2⃗+μb2⃗\vec r = \vec{a_2}+\mu\vec{b_2}, reading off a1⃗,b1⃗,a2⃗,b2⃗\vec{a_1}, \vec{b_1}, \vec{a_2}, \vec{b_2} directly from the given equations.

Step 2. Form the separation vector a2⃗−a1⃗\vec{a_2}-\vec{a_1} by subtracting corresponding components of the two given points.

Step 3. Compute the cross product b1⃗×b2⃗\vec{b_1}\times\vec{b_2} using the 3×33\times3 determinant with ı^,ȷ^,k^\hat\imath,\hat\jmath,\hat k in the top row; this gives the direction of the common perpendicular.

Step 4. Take the dot product of the Step 2 result with the Step 3 result — this scalar triple product is the numerator, and its sign is discarded at the end.

Step 5. Divide by ∣b1⃗×b2⃗∣|\vec{b_1}\times\vec{b_2}| (found from the same cross product in Step 3) and apply the modulus to obtain the final positive distance dd.

Worked example

Problem. Find the shortest distance between the lines r⃗=(ı^+2ȷ^+k^)+λ(ı^−ȷ^+k^)\vec r = (\hat\imath+2\hat\jmath+\hat k) + \lambda(\hat\imath-\hat\jmath+\hat k) and r⃗=(2ı^−ȷ^−k^)+μ(2ı^+ȷ^+2k^)\vec r = (2\hat\imath-\hat\jmath-\hat k) + \mu(2\hat\imath+\hat\jmath+2\hat k).

Step 1. Identify a1⃗=ı^+2ȷ^+k^\vec{a_1}=\hat\imath+2\hat\jmath+\hat k, b1⃗=ı^−ȷ^+k^\vec{b_1}=\hat\imath-\hat\jmath+\hat k, a2⃗=2ı^−ȷ^−k^\vec{a_2}=2\hat\imath-\hat\jmath-\hat k, b2⃗=2ı^+ȷ^+2k^\vec{b_2}=2\hat\imath+\hat\jmath+2\hat k. The direction ratios (1,−1,1)(1,-1,1) and (2,1,2)(2,1,2) are not proportional, so the lines are not parallel and this is a genuine skew-or-intersecting check.

Step 2. Compute the separation: a2⃗−a1⃗=(2−1)ı^+(−1−2)ȷ^+(−1−1)k^=ı^−3ȷ^−2k^\vec{a_2}-\vec{a_1} = (2-1)\hat\imath + (-1-2)\hat\jmath + (-1-1)\hat k = \hat\imath - 3\hat\jmath - 2\hat k.

Step 3. Compute the cross product:

b1⃗×b2⃗=∣ı^ȷ^k^1−11212∣=ı^[(−1)(2)−(1)(1)]−ȷ^[(1)(2)−(1)(2)]+k^[(1)(1)−(−1)(2)]=−3ı^+0ȷ^+3k^\vec{b_1}\times\vec{b_2} = \begin{vmatrix}\hat\imath & \hat\jmath & \hat k \\ 1 & -1 & 1 \\ 2 & 1 & 2\end{vmatrix} = \hat\imath[(-1)(2)-(1)(1)] - \hat\jmath[(1)(2)-(1)(2)] + \hat k[(1)(1)-(-1)(2)] = -3\hat\imath + 0\hat\jmath + 3\hat k

Step 4. Dot the two results: (1)(−3)+(−3)(0)+(−2)(3)=−3+0−6=−9(1)(-3) + (-3)(0) + (-2)(3) = -3 + 0 - 6 = -9.

Step 5. Compute the magnitude ∣b1⃗×b2⃗∣=(−3)2+02+32=18=32|\vec{b_1}\times\vec{b_2}| = \sqrt{(-3)^2+0^2+3^2} = \sqrt{18} = 3\sqrt2, then apply the formula:

d=∣−932∣=932=32=322d = \left|\frac{-9}{3\sqrt2}\right| = \frac{9}{3\sqrt2} = \frac{3}{\sqrt2} = \frac{3\sqrt2}{2}

The shortest distance is 32\dfrac{3}{\sqrt2} units, equivalently 322\dfrac{3\sqrt2}{2} units.

Competitive stretch

Problem. Check whether x−12=y+13=z4\dfrac{x-1}{2}=\dfrac{y+1}{3}=\dfrac{z}{4} and x−31=y−22=z−1−1\dfrac{x-3}{1}=\dfrac{y-2}{2}=\dfrac{z-1}{-1} intersect.

Step 1. Parametrize: line 1 is x=1+2λ, y=−1+3λ, z=4λx=1+2\lambda,\ y=-1+3\lambda,\ z=4\lambda; line 2 is x=3+μ, y=2+2μ, z=1−μx=3+\mu,\ y=2+2\mu,\ z=1-\mu. Equating xx and yy gives 2λ−μ=22\lambda-\mu=2 and 3λ−2μ=33\lambda-2\mu=3, which solve to λ=1,μ=0\lambda=1, \mu=0.

Step 2. Check the zz-equation with these values: line 1 gives z=4(1)=4z=4(1)=4, line 2 gives z=1−0=1z=1-0=1. Since 4≠14 \neq 1, no common λ,μ\lambda,\mu satisfies all three coordinates, so the lines do not intersect; since their direction ratios (2,3,4)(2,3,4) and (1,2,−1)(1,2,-1) are not proportional either, they are skew, and the Case-1 formula above would be applied next to find how far apart they actually are.

Common traps

  • Using the skew-line formula on parallel lines. If b1⃗×b2⃗=0⃗\vec{b_1}\times\vec{b_2}=\vec 0, the Case-1 formula divides by zero — always check for parallel direction ratios first and switch to the Case-2 formula if needed.
  • Sign slip in the cross-product expansion, especially the middle (ȷ^\hat\jmath) term, which carries a built-in minus sign that is easy to drop.
  • Forgetting the final modulus. The scalar triple product in the numerator can be negative; the reported shortest distance is always taken as non-negative.
  • Assuming a nonzero dd automatically means "skew" without checking parallelism. A nonzero distance only rules out intersection — confirm the direction ratios are not proportional before calling the lines skew rather than parallel-and-separated.

Ask the tutor: Want to work through another shortest-distance problem, or verify whether a given pair of lines is parallel, skew, or intersecting? Ask the AI tutor to walk through the calculation with you.

Why does the cross product of the two direction vectors give the direction of the common perpendicular?

The cross product b1⃗×b2⃗\vec{b_1}\times\vec{b_2} is, by definition, perpendicular to both b1⃗\vec{b_1} and b2⃗\vec{b_2} individually. Since b1⃗\vec{b_1} and b2⃗\vec{b_2} are the direction vectors of the two lines, any vector perpendicular to both of them is perpendicular to both lines at once — exactly the direction the common perpendicular segment must point. Projecting the vector joining the two lines onto this direction isolates the true shortest separation, ignoring any sideways component along either line.

What happens if I plug parallel lines into the skew-line formula by mistake?

You get a zero in the denominator, since ∣b1⃗×b2⃗∣=0|\vec{b_1}\times\vec{b_2}|=0 when the directions are parallel, so the calculation is undefined rather than merely wrong. Always compare the direction ratios first: if they are proportional (one is a scalar multiple of the other), the lines are parallel and you must use the separate parallel-lines formula, d=∣b⃗×(a2⃗−a1⃗)∣/∣b⃗∣d = |\vec b \times (\vec{a_2}-\vec{a_1})|/|\vec b|, instead.

If two lines are not parallel, does that automatically mean they are skew?

Not quite — it means they are either skew or intersecting, and you still have to decide which. Compute the scalar triple product (a2⃗−a1⃗)⋅(b1⃗×b2⃗)(\vec{a_2}-\vec{a_1})\cdot(\vec{b_1}\times\vec{b_2}): if it is zero, the two direction vectors and the separation vector are coplanar, and since the lines are not parallel, they must actually cross at a point, so d=0d=0 and they intersect. Only when this triple product is nonzero, giving a genuine positive dd, are the lines truly skew.

Before this

Where this leads