Calculate the distance from a point to a line given as ax + by + c = 0, y = mx + b or two points, plus the closest point on the line.
- All Math and Numbers Calculators
- Distance Between Points Calculator
- Distance From Point to Plane Calculator
- Perpendicular Line Calculator
- Slope Calculator
- Midpoint Calculator
Calculator Functions
The calculator gives the shortest distance from a point to a straight line in the x-y plane, and the point on the line that is closest to it. Select a function to open it in the calculator.
| Function | Use it when | You enter |
|---|---|---|
| Equation ax + by + c = 0 | The line is written with every term on one side | a, b and c |
| Equation y = mx + b | You know the slope and y-intercept of the line | Slope m and y-intercept b |
| Two points on the line | You know two points the line passes through | The coordinates of both points |
Every function also asks for the point (x₀, y₀). Negative numbers and decimals are fine. When every number is whole, the result also shows the exact distance as a fraction or a square root.
Point to Line Distance Formulas
√(a² + b²) [1]
| d | Shortest distance from the point to the line, in the same units as the coordinates |
| a, b | The numbers in front of x and y in the line ax + by + c = 0. They cannot both be 0 |
| c | The constant term of the line |
| x₀, y₀ | Coordinates of the point |
The shortest path from a point to a line always meets the line at a right angle, so this is also called the perpendicular distance.
Equation ax + by + c = 0
The formula above applies directly. Move every term to one side first: 3x + 4y = 5 becomes 3x + 4y − 5 = 0, so c is −5. A vertical line such as x = 4 is a = 1, b = 0 and c = −4.
Equation y = mx + b
√(m² + 1)
Here b is the y-intercept. Writing y = mx + b as mx − y + b = 0 turns it into the general form, with m in front of x and −1 in front of y.
Two points on the line
The line passes through (x₁, y₁) and (x₂, y₂), with Δx = x₂ − x₁ and Δy = y₂ − y₁. The two points must be different.
Closest point on the line
(a² + b²)
x = x₀ − a × t
y = y₀ − b × t
The direction (a, b) is perpendicular to the line [1], so stepping from the point along it reaches the line at its closest point, also called the foot of the perpendicular. The distance d is the length of that step.
Limits of This Estimate
- The line is treated as endless in both directions. For a line segment, check the closest point: if it falls beyond the ends of the segment, the nearest spot is an endpoint, and the Distance Between Points Calculator gives the distance to it.
- It works for flat, two-dimensional coordinates with the same scale on both axes. It does not apply to latitude and longitude or to lines in 3D space. For a point and a plane, use the Distance From Point to Plane Calculator.
- Results are rounded to 4 decimal places. The exact form appears only when every number you enter is whole.
Sources
- Wolfram MathWorld, 2-Dimensional Point-Line Distance: distance formulas for a line in general form and through two points, and the perpendicular direction (a, b)
