The shortest distance from a point (x0,y0) to a line (ax+by+c=0) is essentially the length of the line segment that connects the point and line, and is perpendicular to the line.
In this case, what is the distance of the shortest distance?
(The following will be an algebraic proof of the formula, which only works when we assume that the a and b are not equal to 0)
The line (ax+by+c=0) has slope b−a. Thus, any perpendicular line of ax+by+c=0 has the slope ab.
Let (m,n) be the point of intersection between the perpendicular line (which also passes through (x0,y0) and the original line ax+by+c=0.
x0−my0−n=ab
a(y0−n)−b(x0−m)=0 Square both sides.
a2(y0−n)2+b2(x0−m)2=2ab(y0−n)(x0−m)
Before going on, look at this:
(a(x0−m)+b(y0−n))2
=
a2(x0−m)2+2ab(y0−n)(x0−m)+b2(y0−n)2
=
(a2+b2)((x0−m)2+(y0−n)2)
We also have
(a(x0−m)+b(y0−n))2
=
(ax0+by0−am−bn)2
=
(ax0+by0+c)2
This is because (m,n) is on line ax+by+c=0
Thus,
(a2+b2)((x0−m)2+(y0−n)2)=(ax0+by0+c)2
Now use the distance formula to obtain the length of the line segment obtained by these two points.
d=x(x0−m)2+(y0−n)2
=a2+b2∣ax0+by0+c∣
And the above is the formula for the shortest distance from a point to a line!