The distance from a point to a line

The distance from a point to a line is the shortest gap, measured perpendicular to the line1. You may join the point to any point of the line you like, but the perpendicular segment is the shortest: any slanted segment is the hypotenuse of a right triangle having the perpendicular as a leg, and a hypotenuse is longer than either leg. Here we find the distance from the origin O(0,0)O(0, 0) to the line 3x+4y25=03x + 4y - 25 = 0.

The formula

The distance from a point (x0,y0)(x_0, y_0) to a line ax+by+c=0ax + by + c = 0 is the following.

d=ax0+by0+ca2+b2d = \frac{|a x_0 + b y_0 + c|}{\sqrt{a^2 + b^2}}
PartValue here
Numerator 30+4025|3 \cdot 0 + 4 \cdot 0 - 25|2525
Denominator 32+42\sqrt{3^2 + 4^2}55
Distance dd55

Reading the formula

The numerator is the absolute value of what you get by dropping the coordinates of the point into the left-hand side of the line's equation; if the point lies on the line that value is 00, and so is the distance. The denominator a2+b2\sqrt{a^2 + b^2} is the length of the vector (a,b)(a, b), which points perpendicular to the line, and dividing by it converts the value of the expression into an actual length.

The foot of the perpendicular

The perpendicular dropped from OO to the line is y=43xy = \dfrac{4}{3}x. Substituting into 3x+4y25=03x + 4y - 25 = 0 gives 253x=25\dfrac{25}{3}x = 25, so the foot is (3,4)(3, 4). The length from the origin to (3,4)(3, 4) is 32+42=5\sqrt{3^2 + 4^2} = 5, matching the distance from the formula.

Circles and tangency

This formula is exactly what lies behind comparing the distance from a center to a line with the radius.

Distance versus radiusThe line and the circle
d<rd < rcut at two points
d=rd = rtangent
d>rd > rdo not meet

The circle x2+y2=25x^2 + y^2 = 25 has center (0,0)(0, 0) and radius 55, and the distance is 55, so this line is tangent to it.

The sign tells you the side

Without the absolute value, the sign of ax0+by0+ca x_0 + b y_0 + c tells you which side of the line the point is on. Separating two sides by that sign is the idea behind the machine-learning methods that split data with a line, or a hyperplane2.

The large dots on the graph are the point OO and the foot of the perpendicular; the length of the segment joining them is the distance we wanted.

  1. Distance from a point to a line, Wikipedia
  2. Support vector machine, Wikipedia