Enter a line in standard form, slope-intercept form, or through two points to get the perpendicular distance, projection point, calculation steps, and graph.
Point-to-line distance formula and guide
The perpendicular distance is the length of the shortest segment from a point P to an infinite line. Write the line as Ax + By + C = 0 and the point as (x0, y0). Here, x0 and y0 are the point coordinates, A and B are the components of a normal vector, and C sets the line's offset. A and B cannot both be zero because then no line direction is defined.
How to use the calculator
- Enter the coordinates of point P.
- Paste a complete equation, or choose standard coefficients, slope-intercept, or two-point mode.
- Select precision, answer format, and an optional unit, then calculate.
- Read the conversion, substitution, exact result, decimal result, projection coordinates, and graph.
Formulas for each input form
- Standard:
Ax + By + C = 0 uses the main formula directly. - Slope-intercept: rearrange
y = mx + b to mx − y + b = 0, giving d = |mx₀ − y₀ + b| / √(m² + 1). - Two points: for distinct points
(x₁,y₁) and (x₂,y₂), use A=y₁−y₂, B=x₂−x₁, and C=x₁y₂−x₂y₁.
Projection point
Let k=(Ax₀+By₀+C)/(A²+B²). The perpendicular foot is F=(x₀−Ak, y₀−Bk). This calculator reports F and plots it with a right-angle marker.
Why the formula works
The vector n=(A,B) is normal to the line. The value Ax₀+By₀+C measures the point's offset along that normal, but it is scaled by the length of n. Dividing by ||n||=√(A²+B²) converts that offset to geometric length; the absolute value removes orientation. Equivalently, form a triangle from the point and any two points on the line: its height is twice its area divided by its base length.
Important distinctions and common mistakes
- This page finds distance to an infinite line, not a ray or finite segment. A segment's closest point may be an endpoint if the projection falls outside it.
- Multiplying
A, B, and C by the same nonzero number does not change the distance; the formula is scale-invariant. - Without the absolute value, the result is a signed distance whose sign identifies the side of an oriented line.
- Ordinary regression residuals are usually vertical differences, not perpendicular distances; orthogonal regression uses perpendicular residuals.
- Two-point mode requires distinct points, and slope-intercept form cannot represent a vertical line.
Worked examples
1. Standard form: exact radical
Identify: P=(2,−1) and 2x−y−3=0, so A=2, B=−1, C=−3.
Substitute: d=|2(2)+(−1)(−1)−3|/√(2²+(−1)²).
Simplify: d=2/√5≈0.894427.
Interpret: The point is about 0.894 coordinate units from the line; its perpendicular foot is F=(1.2,−0.6).
2. Slope-intercept form: show the conversion
Identify: P=(3,−1) and y=2x+4.
Convert: 2x−y+4=0, so A=2, B=−1, C=4.
Substitute and simplify: d=|2(3)+(−1)(−1)+4|/√5=11/√5≈4.919350.
Interpret: The projection is F=(−1.4,1.2), 4.919 coordinate units away.
3. Line defined by two points
Identify: P=(4,1); the line passes through P₁=(0,0) and P₂=(3,3).
Convert: A=0−3=−3, B=3−0=3, C=0, giving −3x+3y=0.
Substitute and simplify: d=|−3(4)+3(1)|/√18=9/(3√2)=3/√2≈2.121320.
Interpret: The projection is F=(2.5,2.5).
Special cases
Vertical line: from P=(5,−2) to x=1, d=|5−1|=4. Point on the line: P=(2,3) satisfies x+y−5=0, so the numerator and distance are zero and F=P.
Frequently asked questions
How do I find the distance from a point to a line?
Write the line as Ax + By + C = 0, substitute the point (x0, y0), and calculate |Ax0 + By0 + C| / sqrt(A² + B²). The absolute value makes the distance nonnegative.
How is the slope-intercept distance formula derived?
Rearrange y = mx + b as mx - y + b = 0. Substituting A = m, B = -1, and C = b into the standard formula gives |mx0 - y0 + b| / sqrt(m² + 1).
How do I calculate the distance when the line is defined by two points?
For distinct line points (x1, y1) and (x2, y2), use A = y1 - y2, B = x2 - x1, and C = x1y2 - x2y1, then apply the standard distance formula.
How do vertical lines work?
A vertical line x = k has standard form x - k = 0, so the distance from (x0, y0) is |x0 - k|. Use equation, standard, or two-point mode.
Can the distance be negative?
No. Geometric distance is always zero or positive. Removing the absolute value produces a signed distance that indicates which side of an oriented line contains the point.
What happens when the point lies on the line?
The formula numerator is zero, so the distance is zero and the projection point is the original point.
What units does the answer use?
The distance uses the same unit as the point and line coordinates. If coordinates are in metres, the distance is in metres.
Is distance to an infinite line the same as distance to a line segment?
Not always. This calculator uses an infinite line. For a segment, the closest location can be an endpoint when the perpendicular projection falls outside the segment.
How is the projection point found?
Let k = (Ax0 + By0 + C) / (A² + B²). The perpendicular foot is F = (x0 - Ak, y0 - Bk).
Method, checks, and limitations
The implementation converts every supported input to Ax+By+C=0, evaluates the normal-vector distance formula, and uses orthogonal projection for F. These reference cases are included as transparent checks:
| Point and line | Expected distance | Expected projection |
|---|
(2,−1); 2x−y−3=0 | 2/√5≈0.894427 | (1.2,−0.6) |
(5,−2); x=1 | 4 | (1,−2) |
(2,3); x+y−5=0 | 0 | (2,3) |
Limitations: calculations use browser floating-point arithmetic, so very large or nearly degenerate values can accumulate rounding error. The parser accepts linear equations with numeric coefficients, signed fractions, and simple square roots; it intentionally rejects variables in denominators, powers, functions, and nonlinear terms. Results apply to an infinite 2D line, not a ray or segment.