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→=p−a\overrightarrow{AP} = \mathbf{p}-\mathbf{a}.

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

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

Therefore:

d=∣b×(p−a)∣∣b∣d = \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=(p−a)⋅b∣b∣2\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: p−a\mathbf{p}-\mathbf{a} is parallel to b\mathbf{b}, so b×(p−a)=0\mathbf{b}\times(\mathbf{p}-\mathbf{a}) = \mathbf{0}, giving d=0d = 0.