Understanding the point-to-line distance calculator — concept and principle
The distance from a point to a line is the length of the shortest segment between them, which always meets the line at a right angle. This calculator takes a line written as ax + by + c = 0 and a point (x₀, y₀), and returns that distance together with the foot of the perpendicular, the point on the line closest to the given point. It is used in analytic geometry, in clearance checks on drawings, in computer graphics and collision detection, and in least-squares fitting.
How it is calculated
- Distance: d = |ax₀ + by₀ + c| ÷ √(a² + b²).
- Foot of perpendicular: with t = (ax₀ + by₀ + c) ÷ (a² + b²), the foot is (x₀ − a·t, y₀ − b·t).
a and b cannot both be zero. If your line is in the form y = mx + k, rewrite it as mx − y + k = 0, so a = m, b = −1, c = k.
The principle
The vector (a, b) is perpendicular (normal) to the line ax + by + c = 0. The shortest route from the point to the line therefore runs along this normal direction. Substituting the point into the left side gives the value ax₀ + by₀ + c, which is zero for points on the line and grows in proportion to how far the point lies from it, measured in steps of the normal's length √(a² + b²). Dividing by that length converts the value into an actual distance; the absolute value removes the sign, which only tells you on which side of the line the point is. To find the foot, start at the point and move back along the normal by exactly that amount, which is what the factor t does.
Worked example
- Inputs: line 3x + 4y − 10 = 0, point (5, 6).
- Substitute: 3 × 5 + 4 × 6 − 10 = 15 + 24 − 10 = 29.
- Normal length: √(3² + 4²) = 5.
- Distance: |29| ÷ 5 = 5.8.
- Foot: t = 29 ÷ 25 = 1.16, so (5 − 3 × 1.16, 6 − 4 × 1.16) = (1.52, 1.36). Check: 3 × 1.52 + 4 × 1.36 = 10, so it lies on the line.
| Point y₀ | Distance |
|---|---|
| 1.5 | 2.2 |
| 3 | 3.4 |
| 4.5 | 4.6 |
| 6 | 5.8 |
| 7.5 | 7 |
| 9 | 8.2 |
| 12 | 10.6 |
How to read the result
The distance is always zero or positive; zero means the point is on the line. The sign of ax₀ + by₀ + c (here positive) shows which side of the line the point is on, which is useful for testing whether two points are on the same side. Multiplying the whole equation by a constant, such as 6x + 8y − 20 = 0, does not change the distance, because numerator and denominator scale together.
Common mistakes
- Forgetting to move every term to one side so the equation equals zero before reading a, b and c.
- Dropping the square root in the denominator and dividing by a² + b².
- Using the sign of c incorrectly, for example entering c = 10 for 3x + 4y = 10, which should be c = −10.
Frequently asked questions
How do I find the distance between two parallel lines?
For ax + by + c₁ = 0 and ax + by + c₂ = 0, d = |c₁ − c₂| ÷ √(a² + b²).
How do I get the reflection of the point across the line?
Go twice as far along the normal: (x₀ − 2a·t, y₀ − 2b·t). For the example, (−1.96, −3.28).
Does the formula work for y = mx + k?
Yes, after rewriting: d = |mx₀ − y₀ + k| ÷ √(m² + 1).
Sources: J. Stewart, L. Redlin and S. Watson, Precalculus: Mathematics for Calculus, Cengage · D. Zwillinger (ed.), CRC Standard Mathematical Tables and Formulae, CRC Press, analytic geometry of the plane