Given a line of the form Ax+By+C=0 and a point (h,k), the perpendicular distance from the line to the point is
Consider all the lines perpendicular to Ax+By+C=0. They have the form Bx-Ay+D=0, where A and B are fixed, and D varies to select one of the infinitely many perpendicular lines. To select the line that goes through (h,k), just select D=-(Bh-Ak), so the equation of the line perpendicular to
that passes through (h,k) is
Solving the two lines to find their point of intersection gives us
x = (B2h-ABk-AC)/(A2+B2)
y = (A2k-ABh-BC)/(A2+B2)
Now, the distance from this point of intersection (x,y) to (h,k) is
sqrt((x-h)2+(y-k)2), and then plugging in x and y gives us
which, amazingly, simplifies to
so the final solution is
Lines in 3 dimensions: Equation of a line in three dimensions, the distance between two lines, finding the closest points of the two lines.
The distance from Ax+By+C=0 to a point is used in Tangents to 2 Circles.
An aside in Point and Triangle2 gives the distance dAB from (x,y) to line AB where A=(x1,y1), B=(x2,y2)
Vectors, and their dot product, cross product.
The webmaster and author of this Math Help site is Graeme McRae.