Academy
Formulas/maths/3d Geometry/Distance from a Point to a Line

Distance from a Point to a Line

Distance from point P (position vector p) to the line r = a + λb. The cross product |b × (a−p)| gives the area of the parallelogram with sides b and (a−p); dividing by |b| gives the perpendicular height.
Derivation

Let the line be r=a+λb\mathbf{r} = \mathbf{a}+\lambda\mathbf{b} and the point be PP with position vector p\mathbf{p}.

The vector from the base point AA (position vector a\mathbf{a}) to PP is AP=pa\overrightarrow{AP} = \mathbf{p}-\mathbf{a}.

The area of the parallelogram formed by b\mathbf{b} and (pa)(\mathbf{p}-\mathbf{a}) is b×(pa)|\mathbf{b}\times(\mathbf{p}-\mathbf{a})|.

This area also equals bd|\mathbf{b}| \cdot d where dd is the perpendicular distance from PP to the line.

Therefore:

d=b×(pa)bd = \frac{|\mathbf{b}\times(\mathbf{p}-\mathbf{a})|}{|\mathbf{b}|}

Cartesian method (alternative): Find the foot of perpendicular FF from PP to the line. The foot is at parameter λ0=(pa)bb2\lambda_0 = \frac{(\mathbf{p}-\mathbf{a})\cdot\mathbf{b}}{|\mathbf{b}|^2}. Then d=PF=p(a+λ0b)d = |PF| = |\mathbf{p}-(\mathbf{a}+\lambda_0\mathbf{b})|.

When the point lies on the line: pa\mathbf{p}-\mathbf{a} is parallel to b\mathbf{b}, so b×(pa)=0\mathbf{b}\times(\mathbf{p}-\mathbf{a}) = \mathbf{0}, giving d=0d = 0.