Tutorials › Calculus III › Distance from a Point to a Line

Cross Products, Lines, and Planes · Tutorial 96 of 999

Distance from a Point to a Line

Learn how a line’s direction and a displacement vector determine the shortest distance from a point to that line.

Beginner 9 min read

What You'll Learn

  • Represent a line by a point on it and a nonzero direction vector.
  • Derive the point-to-line distance formula from perpendicular and parallel components.
  • Apply the cross-product formula to lines in three-dimensional space.
  • Find the closest point on a line and use it to check a distance calculation.
  • Recognize why the cross product’s magnitude, not its direction, gives the relevant distance.

Introduction

A point and a line in three-dimensional space are usually not enough information to determine a distance by simply subtracting coordinates: the shortest connecting segment may not point in the same direction as the line. The line’s direction matters because it tells us which part of the displacement from the line to the point is parallel to the line and which part is perpendicular.

The cross product gives a direct way to isolate the perpendicular contribution. Its magnitude measures the area of a parallelogram, so dividing that area by the length of the line’s direction vector produces the shortest distance.

Representing a Line and a Point

Write a line \(L\) in point-direction form as \(\mathbf{r}=\mathbf{a}+t\mathbf{v}\), where \(\mathbf{a}\) is the position vector of a point \(A\) on the line, \(\mathbf{v}\) is a nonzero direction vector, and \(t\) ranges over the real numbers. Let \(Q\) be the point whose distance from the line is required, with position vector \(\mathbf{q}\).

Definition: The distance from a point \(Q\) to a line \(L\) is the smallest length of a segment joining \(Q\) to any point on \(L\). For a line \(\mathbf{r}=\mathbf{a}+t\mathbf{v}\), where \(\mathbf{v}\ne\mathbf{0}\), this distance is \[ d(Q,L)=\frac{\left\lVert(\mathbf{q}-\mathbf{a})\times\mathbf{v}\right\rVert}{\lVert\mathbf{v}\rVert}. \]

Here \(\mathbf{q}-\mathbf{a}\) is the displacement from the chosen point \(A\) on the line to \(Q\). The denominator is nonzero because the direction vector of a line must be nonzero. The result is a nonnegative length.

Why the Cross-Product Formula Works

Let \(\mathbf{d}=\mathbf{q}-\mathbf{a}\). Split this displacement into a component parallel to the line and a component perpendicular to it: \(\mathbf{d}=\mathbf{d}_{\parallel}+\mathbf{d}_{\perp}\). The parallel component is the projection of \(\mathbf{d}\) onto the nonzero vector \(\mathbf{v}\): \[ \mathbf{d}_{\parallel}=\frac{\mathbf{d}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}}\mathbf{v}, \qquad \mathbf{d}_{\perp}=\mathbf{d}-\mathbf{d}_{\parallel}. \] By construction, \(\mathbf{d}_{\perp}\cdot\mathbf{v}=0\).

The point on the line with parameter \(t_*=(\mathbf{d}\cdot\mathbf{v})/(\mathbf{v}\cdot\mathbf{v})\) has position vector \(\mathbf{a}+t_*\mathbf{v}\). The displacement from this point on the line to \(Q\) is exactly \(\mathbf{d}_{\perp}\), so its length is \(\lVert\mathbf{d}_{\perp}\rVert\).

Why this point is closest: For any real parameter \(t\), the displacement from \(\mathbf{a}+t\mathbf{v}\) to \(Q\) is \(\mathbf{d}_{\perp}+(t_*-t)\mathbf{v}\). Its two terms are perpendicular. Therefore its squared length is \[ \left\lVert\mathbf{d}_{\perp}+(t_*-t)\mathbf{v}\right\rVert^2 = \lVert\mathbf{d}_{\perp}\rVert^2+(t_*-t)^2\lVert\mathbf{v}\rVert^2 \geq \lVert\mathbf{d}_{\perp}\rVert^2. \] Equality occurs at \(t=t_*\). Thus the perpendicular segment has the minimum possible length.

It remains to relate this perpendicular length to a cross product. Since \(\mathbf{d}_{\parallel}\) is a scalar multiple of \(\mathbf{v}\), its cross product with \(\mathbf{v}\) is zero. Consequently, \(\mathbf{d}\times\mathbf{v}=\mathbf{d}_{\perp}\times\mathbf{v}\). The magnitude of the resulting cross product is the length of the perpendicular component multiplied by the direction-vector length: \[ \lVert\mathbf{d}\times\mathbf{v}\rVert = \lVert\mathbf{d}_{\perp}\rVert\lVert\mathbf{v}\rVert. \] This follows from the cross-product magnitude identity \(\lVert\mathbf{x}\times\mathbf{y}\rVert^2 =\lVert\mathbf{x}\rVert^2\lVert\mathbf{y}\rVert^2-(\mathbf{x}\cdot\mathbf{y})^2\), applied to perpendicular vectors. Dividing by \(\lVert\mathbf{v}\rVert\) proves the formula.

The cross product does not point in the direction of the perpendicular displacement. It points perpendicular to both vectors being crossed. It is its magnitude that gives the perpendicular distance after division by \(\lVert\mathbf{v}\rVert\).

Applying the Formula

Worked Example: A Point and a Line in Point-Direction Form

Find the distance from \(Q=(4,1,3)\) to the line through \(A=(1,2,-1)\) with direction vector \(\mathbf{v}=\langle 2,-1,2\rangle\). First find the displacement from \(A\) to \(Q\): \[ \mathbf{d}=\overrightarrow{AQ} =\langle 4-1,1-2,3-(-1)\rangle =\langle 3,-1,4\rangle. \]

Compute the cross product, keeping the order \(\mathbf{d}\times\mathbf{v}\): \[ \mathbf{d}\times\mathbf{v} = \langle (-1)(2)-4(-1),\;4(2)-3(2),\;3(-1)-(-1)(2)\rangle = \langle 2,2,-1\rangle. \] Its magnitude is \(\sqrt{2^2+2^2+(-1)^2}=\sqrt{9}=3\). The direction vector has magnitude \(\sqrt{2^2+(-1)^2+2^2}=\sqrt{9}=3\). Therefore, \[ d(Q,L)=\frac{3}{3}=1. \]

Check using the closest point. The parameter of that point is \[ t_*=\frac{\mathbf{d}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}} =\frac{3(2)+(-1)(-1)+4(2)}{2^2+(-1)^2+2^2} =\frac{6+1+8}{9} =\frac{5}{3}. \] Thus the closest point is \[ H=A+\frac{5}{3}\mathbf{v} =\left(1+\frac{10}{3},\,2-\frac{5}{3},\,-1+\frac{10}{3}\right) =\left(\frac{13}{3},\frac{1}{3},\frac{7}{3}\right). \] The displacement from \(H\) to \(Q\) is \[ \overrightarrow{HQ} =\left(4-\frac{13}{3},\,1-\frac{1}{3},\,3-\frac{7}{3}\right) =\left(-\frac{1}{3},\frac{2}{3},\frac{2}{3}\right), \] whose length is \(\sqrt{1/9+4/9+4/9}=\sqrt{1}=1\), as required. Also, \(\overrightarrow{HQ}\cdot\mathbf{v}=-2/3-2/3+4/3=0\), confirming the segment is perpendicular to the line.

When the Distance Is Not an Integer

Worked Example: A Distance Involving a Radical

Find the distance from \(Q=(3,0,1)\) to the line through \(A=(0,1,2)\) with direction vector \(\mathbf{v}=\langle 1,2,2\rangle\). The displacement is \[ \mathbf{d}=\overrightarrow{AQ} =\langle 3-0,0-1,1-2\rangle =\langle 3,-1,-1\rangle. \]

Compute the cross product: \[ \mathbf{d}\times\mathbf{v} = \langle (-1)(2)-(-1)(2),\;(-1)(1)-3(2),\;3(2)-(-1)(1)\rangle = \langle 0,-7,7\rangle. \] Its magnitude is \(\sqrt{0^2+(-7)^2+7^2}=\sqrt{98}=7\sqrt{2}\). The direction vector has magnitude \(\sqrt{1^2+2^2+2^2}=3\). Hence \[ d(Q,L)=\frac{7\sqrt{2}}{3}. \]

For a check, the closest parameter is \[ t_*=\frac{\mathbf{d}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}} =\frac{3(1)+(-1)(2)+(-1)(2)}{1^2+2^2+2^2} =\frac{-1}{9}. \] The point on the line is \[ H=A-\frac{1}{9}\mathbf{v} =\left(-\frac{1}{9},\frac{7}{9},\frac{16}{9}\right). \] Then \[ \overrightarrow{HQ} =\left(3+\frac{1}{9},-\frac{7}{9},1-\frac{16}{9}\right) =\left(\frac{28}{9},-\frac{7}{9},-\frac{7}{9}\right). \] Its squared length is \[ \left(\frac{28}{9}\right)^2+ \left(-\frac{7}{9}\right)^2+ \left(-\frac{7}{9}\right)^2 =\frac{784+49+49}{81} =\frac{882}{81} =\frac{98}{9}. \] Thus its length is \(\sqrt{98/9}=7\sqrt{2}/3\), agreeing with the cross-product calculation. The perpendicular check is \(\overrightarrow{HQ}\cdot\mathbf{v}=28/9-14/9-14/9=0\).

Using the Formula with a Different Direction

A direction vector can be multiplied by any nonzero scalar without changing the line. The formula remains unchanged: multiplying \(\mathbf{v}\) by a nonzero scalar multiplies both the cross-product magnitude and the denominator by the scalar’s absolute value. The point \(A\) may also be replaced by any other point on the same line, because that changes \(\mathbf{q}-\mathbf{a}\) only by a multiple of \(\mathbf{v}\), whose cross product with \(\mathbf{v}\) is zero.

Worked Example: Checking with a Rescaled Direction Vector

Let \(Q=(5,2,1)\), and let the line pass through \(A=(2,-1,0)\) with direction vector \(\mathbf{v}=\langle 0,3,4\rangle\). The displacement is \[ \mathbf{d}=\overrightarrow{AQ} =\langle 5-2,2-(-1),1-0\rangle =\langle 3,3,1\rangle. \] The cross product and its magnitude are \[ \mathbf{d}\times\mathbf{v} =\langle 3(4)-1(3),\,1(0)-3(4),\,3(3)-3(0)\rangle =\langle 9,-12,9\rangle, \] \[ \lVert\mathbf{d}\times\mathbf{v}\rVert =\sqrt{81+144+81} =\sqrt{306} =3\sqrt{34}. \] Since \(\lVert\mathbf{v}\rVert=\sqrt{0^2+3^2+4^2}=5\), the distance is \[ d(Q,L)=\frac{3\sqrt{34}}{5}. \]

Now use the alternative direction vector \(\mathbf{w}=2\mathbf{v}=\langle 0,6,8\rangle\). Then \[ \mathbf{d}\times\mathbf{w} =\langle 18,-24,18\rangle, \qquad \lVert\mathbf{d}\times\mathbf{w}\rVert =\sqrt{324+576+324} =\sqrt{1224} =6\sqrt{34}, \] and \(\lVert\mathbf{w}\rVert=\sqrt{0+36+64}=10\). The distance is again \[ \frac{\lVert\mathbf{d}\times\mathbf{w}\rVert}{\lVert\mathbf{w}\rVert} =\frac{6\sqrt{34}}{10} =\frac{3\sqrt{34}}{5}. \] For a closest-point check, \(t_*=13/25\), since \[ \frac{\mathbf{d}\cdot\mathbf{v}}{\mathbf{v}\cdot\mathbf{v}} =\frac{0+9+4}{25} =\frac{13}{25}. \] Thus \(H=(2,14/25,52/25)\), and \(\overrightarrow{HQ}=(3,36/25,-27/25)\). Its dot product with \(\mathbf{v}\) is \(108/25-108/25=0\), and its squared length is \[ 9+\frac{1296}{625}+\frac{729}{625} =9+\frac{2025}{625} =9+\frac{81}{25} =\frac{306}{25}. \] Therefore its length is \(3\sqrt{34}/5\), confirming the result.

A Common Cross-Product Mistake

It is important not to treat the cross product itself as the perpendicular displacement. In the first worked example, \(\mathbf{d}=\langle 3,-1,4\rangle\), \(\mathbf{v}=\langle 2,-1,2\rangle\), and \(\mathbf{d}\times\mathbf{v}=\langle 2,2,-1\rangle\). A mistaken calculation might claim that the perpendicular displacement is \[ \frac{\mathbf{d}\times\mathbf{v}}{\lVert\mathbf{v}\rVert} =\left\langle\frac{2}{3},\frac{2}{3},-\frac{1}{3}\right\rangle. \] That is incorrect: this vector is not the displacement from the closest point on the line to \(Q\). In fact, the actual perpendicular displacement is \[ \mathbf{d}_{\perp} =\mathbf{d}-\frac{5}{3}\mathbf{v} =\left\langle-\frac{1}{3},\frac{2}{3},\frac{2}{3}\right\rangle. \] The two vectors differ in direction, though both have length \(1\). The correct use of the cross product is to take its magnitude and divide by the direction-vector length; the formula gives a distance, not the perpendicular displacement vector.

A second error is to divide by \(\lVert\mathbf{v}\rVert^2\) instead of \(\lVert\mathbf{v}\rVert\). The cross-product magnitude represents area and equals the perpendicular distance times \(\lVert\mathbf{v}\rVert\), not times its square. Always use \(\lVert\mathbf{d}\times\mathbf{v}\rVert/\lVert\mathbf{v}\rVert\).

Using the Distance Formula Reliably

A careful calculation follows a short sequence. First identify a point on the line and a nonzero direction vector. Next subtract the line point’s coordinates from the point’s coordinates to form \(\mathbf{d}\). Then compute \(\mathbf{d}\times\mathbf{v}\), take its magnitude, and divide by \(\lVert\mathbf{v}\rVert\). Keep the order of the cross product consistent; reversing it changes the cross product’s sign, but not its magnitude.

This method is useful whenever the line is given by a point and direction, including when it is written parametrically. It measures the perpendicular separation from the point to the entire line, not the distance to an arbitrary point chosen on that line. If the point lies on the line, \(\mathbf{d}\) is parallel to \(\mathbf{v}\), so the cross product is zero and the distance is zero, as it should be.

Check Your Understanding

Use the definition and the worked steps to answer these questions. When a calculation is requested, show the cross product and both magnitudes.

  1. For a line \(\mathbf{r}=\mathbf{a}+t\mathbf{v}\), what conditions must \(\mathbf{a}\) and \(\mathbf{v}\) satisfy for the point-to-line distance formula to apply?
  2. Explain why the cross product removes the parallel component of the displacement.
  3. Why does the formula use the magnitude of the cross product rather than treating the cross product as the shortest connecting vector?
  4. Find the distance from \(Q=(1,2,0)\) to the line through \(A=(0,0,0)\) with direction vector \(\langle 1,0,1\rangle\).
  5. If a line’s direction vector is replaced by three times that vector, what happens to the numerator and denominator of the distance formula?