1001Ferramentas
📏 Calculators

Point Line Distance 2D Calculator

Computes distance from a point to a line in the plane given line coefficients a x plus b y plus c equals zero and point coordinates.

Distance from a point to a line in 2D

Take a line in general form a·x + b·y + c = 0 and a point P = (x₀, y₀). The perpendicular distance from P to the line is d = |a·x₀ + b·y₀ + c| / √(a² + b²). Up top you have the signed value of the line equation evaluated at P, which is zero exactly when P sits on the line. Dividing by √(a² + b²) scales the normal vector (a, b) down to unit length. Try it: the distance from P = (1, 2) to the line x + y − 3 = 0 is |1 + 2 − 3| / √(1² + 1²) = 0 / √2 = 0, so P lands right on the line. Move to P = (4, 5) with the same line and you get |4 + 5 − 3| / √2 = 6/√2 ≈ 4.243.

Applications

It shows up in GIS proximity queries (how far is a building from the nearest road centreline?), CAD geometric constraints like snap-to-line and perpendicularity, and computer graphics for anti-aliasing thin lines. In linear regression the residuals are vertical distances to the fitted line, while orthogonal regression reaches for this formula directly. You'll also see it in Hough transform peak detection and in robotics path planning, where it measures clearance from a wall modelled as a line.

FAQ

What if I have the line in slope-intercept form y = m·x + k? Rearrange it to m·x − y + k = 0, so a = m, b = −1, c = k. That gives d = |m·x₀ − y₀ + k| / √(m² + 1).

What if a = b = 0? Then the "line" collapses. There's no line at all, only the equation c = 0, and the formula ends up dividing by zero. Reject the input as invalid.

How do I find the foot of the perpendicular? The point on the line nearest to P is P − ((a·x₀ + b·y₀ + c)/(a² + b²)) · (a, b). Keep the same scalar but drop the absolute value and you get a signed projection along the normal.

Related Tools