How to Find the Distance from a Point to a Line

Calculates the distance between the line ax + by + c = 0 and the point (x, y) as |ax + by + c| ÷ √(a² + b²). The nearest point on the line, the foot of the perpendicular, is also shown.

This finds the distance between the line ax+by+c=0ax + by + c = 0 and the point (x,y)(x, y), meaning the length of the perpendicular dropped from the point to the line.

d=ax+by+ca2+b2d = \dfrac{|ax + by + c|}{\sqrt{a^2 + b^2}}

aa, bb and cc are the coefficients of the line, (x,y)(x, y) is the point and dd is the distance. The nearest point on the line, the foot of the perpendicular, is also given.

What the two parts do

The top, ax+by+cax + by + c, is what you get by putting the point into the equation of the line. It is 0 when the point lies on the line and grows as the point moves away. That value scales with the size of the coefficients, so dividing by a2+b2\sqrt{a^2 + b^2} turns it into a length that does not depend on how the line was written. The absolute value keeps the distance positive on either side of the line.

Example

For the line 3x+4y5=03x + 4y - 5 = 0 and the point (2,3)(2, 3), the top is 3×2+4×35=13|3 \times 2 + 4 \times 3 - 5| = 13 and the bottom is 32+42=5\sqrt{3^2 + 4^2} = 5, so d=13÷5=2.6d = 13 \div 5 = 2.6. The foot of the perpendicular is (0.44,0.92)(0.44, 0.92).

Notes

Write the line as ax+by+c=0ax + by + c = 0. A line given as y=2x+1y = 2x + 1 becomes 2xy+1=02x - y + 1 = 0.

With aa and bb both 0 the equation is not a line at all, so nothing can be calculated.