Academy
Formulas/maths/Straight Lines/Distance from a Point to a Line

Distance from a Point to a Line

Perpendicular distance from point (x₁, y₁) to the line ax + by + c = 0.
Derivation

Given point P(x1,y1)P(x_1, y_1) and line L:ax+by+c=0L: ax + by + c = 0.

Write LL in normal form by dividing by a2+b2\sqrt{a^2+b^2}:

aa2+b2x+ba2+b2y+ca2+b2=0\frac{a}{\sqrt{a^2+b^2}}x + \frac{b}{\sqrt{a^2+b^2}}y + \frac{c}{\sqrt{a^2+b^2}} = 0

In normal form xcosα+ysinα=px\cos\alpha + y\sin\alpha = p, the signed distance from any point (x1,y1)(x_1,y_1) to the line is (x1cosα+y1sinαp)(x_1\cos\alpha + y_1\sin\alpha - p). Substituting:

signed distance=ax1+by1+ca2+b2\text{signed distance} = \frac{ax_1 + by_1 + c}{\sqrt{a^2+b^2}}

The sign indicates which side of the line PP lies on. The perpendicular distance is:

d=ax1+by1+ca2+b2\boxed{d = \frac{|ax_1 + by_1 + c|}{\sqrt{a^2 + b^2}}}
Key Idea
Vector form. Let $A$ be any point on $L$, and $\vec{d} = (b, -a)$ a direction vector along $L$ (perpendicular to the normal $(a,b)$). Then the distance from $P$ to $L$ is the magnitude of the component of $\overrightarrow{AP}$ perpendicular to $\vec{d}$:
> > $$ > d = \frac{|\overrightarrow{AP} \times \vec{d}|}{|\vec{d}|} > $$ > > where $\times$ denotes the 2D cross product (z-component of the 3D cross product). Taking $A$ as any point satisfying $ax + by + c = 0$ and computing recovers the same formula. This is the form used in 3D for distance from a point to a line in space.