Point to Line Distance (2D) — Perpendicular Distance

Compute the shortest distance from a point to a line. Private by design—everything runs locally in your browser.

Point, Line & Actions

d = —

Formula (standard form): d = |A x₀ + B y₀ + C| / √(A² + B²). Tip: Press Enter in any field to calculate.

Preview

The blue line is infinite. The red segment shows the perpendicular distance from your point to the line.

Perpendicular Distance from a Point to a Line (2D)

For a line given by A x + B y + C = 0 and a point P=(x₀,y₀), the perpendicular distance is d = |A x₀ + B y₀ + C| / √(A² + B²).

If you prefer y = m x + b, the equivalent standard form is -m x + 1·y - b = 0 (so A=-m, B=1, C=-b). For a line through points P₁=(x₁,y₁) and P₂=(x₂,y₂), one valid standard form is: A = y₁ - y₂, B = x₂ - x₁, C = x₁ y₂ - x₂ y₁.

How This Calculator Works

  • Accepts the line in three common forms and converts to Ax+By+C=0 internally.
  • Computes the perpendicular foot and distance.
  • Shows a shareable URL and a clean, scaled visual.
  • Everything runs locally for full privacy.

Point→Line Distance: Frequently Asked Questions

What if the point lies on the line?

The distance is zero and the perpendicular foot equals the point.

What inputs are invalid?

Standard form with A=B=0, or Two Points with identical points. For vertical lines, use Standard or Two Points.

How precise is the result?

Calculations use full floating-point precision and are displayed rounded to 6 decimals by default.

Perpendicular Distance in 2D: What It Is and How to Compute It

The perpendicular (shortest) distance from a point to a line is a staple result in analytic geometry, computer graphics, robotics, surveying, GIS, and more. Given a point P=(x₀, y₀) and a line, we measure how far you’d travel along a direction that is orthogonal to the line to reach it. This calculator supports three common line forms and converts everything into the robust standard form A x + B y + C = 0.

Core Formula (Standard Form)

If the line is A x + B y + C = 0, the perpendicular distance is:
d = |A x₀ + B y₀ + C| / √(A² + B²).

This expression is scale-invariant: multiplying (A, B, C) by any nonzero constant does not change the result, because both numerator and denominator scale together.

Other Forms You Can Use

  • Slope–intercept y = m x + b  ⇒  rewrite as -m x + 1·y - b = 0, so A = -m, B = 1, C = -b. Then apply the core formula. A compact version is d = |m x₀ - y₀ + b| / √(m² + 1).
  • Two-point form with P₁=(x₁, y₁), P₂=(x₂, y₂) (distinct): a convenient determinant form is d = |(x₂ - x₁)(y₁ - y₀) - (x₁ - x₀)(y₂ - y₁)| / √((x₂ - x₁)² + (y₂ - y₁)²).

Perpendicular Foot (Projection Point)

Often you also want where the perpendicular meets the line. For A x + B y + C = 0, let k = (A x₀ + B y₀ + C) / (A² + B²). Then the foot F=(x_f, y_f) is x_f = x₀ - A k, y_f = y₀ - B k. If the distance is zero, P already lies on the line and F = P.

Signed vs. Unsigned Distance

This tool reports the unsigned distance. If you need a signed distance, drop the absolute value: d_s = (A x₀ + B y₀ + C) / √(A² + B²). The sign tells you on which side of the oriented line the point falls (based on the direction of the normal vector (A, B)).

Worked Example

Point P=(2, -1), line 2x − y − 3 = 0. Then d = |2·2 + (−1)·(−1) − 3| / √(2² + (−1)²) = |4 + 1 − 3| / √5 = 2 / √5 ≈ 0.894427. For the foot: k = (2·2 + (−1)·(−1) − 3)/(2² + (−1)²) = 2/5, so x_f = 2 − 2·(2/5) = 1.2, y_f = −1 − (−1)·(2/5) = −0.6.

Tips & Pitfalls

  • For vertical lines, prefer Ax+By+C=0 or the two-point form; y=mx+b cannot represent verticals.
  • Ensure two distinct points when using the two-point form.
  • No need to “normalize” (A,B,C); the formula handles scaling automatically.

Applications include measuring shortest offsets to roads or edges (GIS), snapping objects to guides (graphics/CAD), collision & steering behaviors (games/robotics), residuals in linear regression, and more.

Explore more tools