Distance from a point to a line

Find the shortest distance from a point to a line. Give the line by its equation ax + by + c = 0 or by two points on it; two points also work in three dimensions. You also get the foot of the perpendicular, the closest point on the line.

Coordinates separated by commas: 5, 5 or 1, 0, 0.
Used with the equation. For 3x + 4y − 10 = 0 type 3, 4, -10. For y = 2x + 1 type 2, -1, 1.
Used with two points. Same number of coordinates as P.
A second, different point on the line.
Distance5
Foot of the perpendicular (closest point)
(2, 1)
Signed distance (side of the line)
5
Line equation
3x + 4y − 10 = 0

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Choose how the line is given: an equation or two points.
  2. Enter the point P, for example 5, 5.
  3. For the equation, enter a, b, c (3, 4, -10 for 3x + 4y − 10 = 0); for two points, enter A and B.

How it works

  • Equation: d = |ax₀ + by₀ + c| / √(a² + b²). The foot is P − ((ax₀ + by₀ + c)/(a² + b²))·(a, b).
  • Two points: with the direction d = B − A, the parameter t = (P − A)·d / (d·d) gives the foot A + t·d, and the distance is the length from P to the foot. This works the same way in 2D and 3D. In 2D the line equation through A and B is shown too.

Worked example

Line 3x + 4y − 10 = 0, point P(5, 5): 3·5 + 4·5 − 10 = 25, √(9 + 16) = 5, so d = 25/5 = 5. The foot is (5, 5) − 25/25·(3, 4) = (2, 1); check: 3·2 + 4·1 − 10 = 0.

In space: the line through A(0, 0, 0) and B(1, 1, 1) and P(1, 0, 0). t = 1/3, the foot is (1/3, 1/3, 1/3) and d = √(2/3) = 0.8164965809.

Tips and common mistakes

  • Forgetting the square root in the denominator is the classic error; |ax₀ + by₀ + c| alone is not a distance unless a² + b² = 1.
  • Keep the signs: the line 3x + 4y = 10 has c = −10.
  • A t between 0 and 1 means the foot lies between A and B; outside that range it is on the extension of the segment.

Frequently asked questions

What is the formula for the distance from a point to a line?

For the line ax + by + c = 0 and the point (x₀, y₀): d = |ax₀ + by₀ + c| / √(a² + b²). For a line through A and B in 2D or 3D: d = ‖(P − A) − t(B − A)‖ with t = (P − A)·(B − A) / ‖B − A‖².

What is the foot of the perpendicular?

The point on the line closest to P. The segment from P to it is perpendicular to the line and its length is the distance.

What does the sign of the signed distance mean?

(ax₀ + by₀ + c)/√(a² + b²) is positive on the side the normal vector (a, b) points to and negative on the other side. Its absolute value is the distance.

How do I enter a line like y = mx + k?

Move everything to one side: mx − y + k = 0, so a = m, b = −1, c = k. For y = 2x + 1 enter 2, -1, 1.

More in Math

All tools in this category: Math ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.