The shortest way to a line
The distance from a point to a line is always measured along the perpendicular: any other path to the line is longer. This simple idea appears in geometry homework, but also in surveying, computer graphics, robotics and data fitting.
The formula
For a line written as ax + by + c = 0 and a point (x₀, y₀):
d = |ax₀ + by₀ + c| ÷ √(a² + b²)
The numerator tells how far the point is from satisfying the line’s equation; the denominator rescales it to a true distance. The sign of ax₀ + by₀ + c, before taking the absolute value, tells which side of the line the point is on.
The foot of the perpendicular
The closest point on the line, called the foot of the perpendicular or the orthogonal projection, is:
- x = x₀ − a·t
- y = y₀ − b·t
with t = (ax₀ + by₀ + c) ÷ (a² + b²).
Lines through two points
When the line passes through (x₁, y₁) and (x₂, y₂), its coefficients are a = y₂ − y₁, b = x₁ − x₂ and c = x₂y₁ − x₁y₂. The calculator converts the points for you and also gives the distance to the segment between them: if the foot of the perpendicular falls beyond either end, the nearest point of the segment is that endpoint.
Worked example
Find the distance from (5, 5) to the line 3x + 4y − 10 = 0.
- Numerator: |3 × 5 + 4 × 5 − 10| = 25.
- Denominator: √(9 + 16) = 5.
- Distance: 5.
- t = 25 ÷ 25 = 1, so the foot of the perpendicular is (5 − 3, 5 − 4) = (2, 1).
Check: (2, 1) satisfies 3 × 2 + 4 × 1 − 10 = 0, and the distance from (5, 5) to (2, 1) is √(9 + 16) = 5.
Where it is used
- Surveying and mapping: the offset of a point from a property line or a road centerline.
- Computer graphics and games: detecting when an object touches a wall, or selecting the line nearest a mouse click.
- Statistics: orthogonal regression minimizes the perpendicular distances from data points to a line, unlike ordinary least squares, which uses vertical distances.
- Navigation: the cross-track error of a ship or aircraft from its planned course, over short distances where the Earth’s curvature can be ignored.
Special cases
If the point lies on the line, the distance is 0. If a and b are both zero, or the two points are identical, there is no line, and the calculator shows a warning.