Skip to content
Omnikalc

Distance from a point to a line, with the foot of the perpendicular

Calculate the shortest distance from a point to a line given by its equation or by two points, the foot of the perpendicular, and the distance to the segment.

Updated on
Your inputs
Line given by

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Results

Distance from the point to the line

5

d = |ax₀ + by₀ + c| ÷ √(a² + b²)

Foot of the perpendicular: x

2

Foot of the perpendicular: y

1

Distance to the segment between the two points
5
Line equation: a
3
Line equation: b
4
Line equation: c
-10

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.

Frequently asked questions

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

For a line ax + by + c = 0 and a point (x₀, y₀), the distance is |ax₀ + by₀ + c| ÷ √(a² + b²). It measures along the perpendicular, the shortest path to the line.

What is the foot of the perpendicular?

The point on the line closest to the given point, where the perpendicular meets the line. Its coordinates are (x₀ − a·t, y₀ − b·t), with t = (ax₀ + by₀ + c) ÷ (a² + b²).

How do I get the equation from two points?

For a line through (x₁, y₁) and (x₂, y₂): a = y₂ − y₁, b = x₁ − x₂ and c = x₂y₁ − x₁y₂. The calculator does this when you choose the two-point mode.

What is the distance to a segment?

If the foot of the perpendicular falls outside the segment, the closest point is the nearer endpoint. The calculator gives this distance too, which is useful in mapping and collision detection.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.