## Proof of Formula for Distance Between Line and Point in 2D

Find the least distance of the line
$ax+by=c$
from the point
$(x_0,y_0)$

Rearrange the line as
$y=- \frac{a}{b}x+ \frac{c}{b}$
.
The gradient of this line is
$- \frac{a}{b}$
.
The gradient of the perpendicular line is
$\frac{b}{a}$
.
The perpendicular line passes through the point
$(x_0,y_0)$
.
$y_0=\frac{b}{a}x_0+c \rightarrow c=y_0- \frac{b}{a}x_0$

The equation of the perpendicular line is
$y=\frac{b}{a}x+y_0- \frac{b}{a}x_0$
Now find the point of intersection of these two lines by solving the simultaneous equations
$ax+by=c, \; y=\frac{b}{a}x+y_0- \frac{b}{a}x_0$
, equivalent to
$ax+by=c$
(1)
$bx-ay=bx_0-ay_0$
(2)
$a$
times (1) to
$b$
times (2) to give
$a^2x+b^2x=ac-aby_0-a^2x_0 \rightarrow x= \frac{ac-aby_0-a^2x_0}{a^2+b^2}$
.
Subtract
$a$
times (2) from
$b$
times (1) to give
$a^2y+b^2y= bc-abx_0+a^2y_0 \rightarrow y= \frac{bc-abx_0+a^2y_0}{a^2+b^2}$
.
The distance
$d$
is then the distance between the points
$(0,0)$
and
$(\frac{ac-aby_0-a^2x}{a^2+b^2}, \frac{bc-abx_0+a^2y_0}{a^2+b^2})$

\begin{aligned} d &=\sqrt{(\frac{ac-aby_0+b^2x_0}{a^2+b^2}-x_0)^2+(\frac{bc-abx_0+a^2y_0}{a^2+b^2}-y_0)^2} \\ &=\sqrt{(\frac{ac-aby_0-a^2x_0}{a^2+b^2})^2+(\frac{bc-abx_0-b^2y_0}{a^2+b^2})^2} \\ &= \sqrt{\frac{(a^2+b^2)(c-by_0-ax_0)^2}{a^2+b^2)^2}} \\ &= \frac{c-ax_0-by_0}{\sqrt{a^2+b^2}}\end{aligned}