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.

For a line in general (standard) form. Move every term to one side first.

Blank counts as 0, a line through the origin.

Optional settings

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.

FunctionUse it whenYou enter
Equation ax + by + c = 0The line is written with every term on one sidea, b and c
Equation y = mx + bYou know the slope and y-intercept of the lineSlope m and y-intercept b
Two points on the lineYou know two points the line passes throughThe 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

d = |ax₀ + by₀ + c| ÷
√(a² + b²) [1]
dShortest distance from the point to the line, in the same units as the coordinates
a, bThe numbers in front of x and y in the line ax + by + c = 0. They cannot both be 0
cThe 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

d = |mx₀ − y₀ + 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

d = |Δx(y₁ − y₀) −
Δy(x₁ − x₀)| ÷
√(Δx² + Δy²) [1]

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

t = (ax₀ + by₀ + c) ÷
(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

  1. 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)