Skip to content

Distance from Point to Line Calculator

Updated:

Enter the coordinates of a point and the coefficients of a line in the form Ax + By + C = 0 to find the shortest (perpendicular) distance between them, with full calculation steps.

Find the Perpendicular Distance from a Point to a Line

Input Fields
Point P
x₁
Horizontal coordinate of the point.
y₁
Vertical coordinate of the point.
Line Ax + By + C = 0
A
Coefficient of x in the line equation.
B
Coefficient of y in the line equation.
C
Constant term of the line equation.
If enabled, the result will update automatically when you change any value.

Distance from Point to Line Formula

Formula
\[ d = \frac{|A x_1 + B y_1 + C|}{\sqrt{A^2 + B^2}} \]

Where:

  • \(d\) — perpendicular distance from the point to the line (units)
  • \(x_1, y_1\) — coordinates of the point P
  • \(A, B, C\) — coefficients of the line \(Ax + By + C = 0\)

The formula measures how far the point lies from the line along the shortest possible path — the perpendicular. The numerator evaluates the line's equation at the point, and the denominator \(\sqrt{A^2 + B^2}\) normalizes the coefficients so the result is a true Euclidean distance.

Distance from Point to Line – Calculation Example

Example: find the distance from the point P(3, 4) to the line \(2x - y + 1 = 0\).

\[ A x_1 + B y_1 + C = 2 \cdot 3 + (-1) \cdot 4 + 1 = 6 - 4 + 1 = 3 \]

\[ d = \frac{|3|}{\sqrt{2^2 + (-1)^2}} = \frac{3}{\sqrt{5}} \approx 1.342 \text{ units} \]

Result: the shortest distance from P(3, 4) to the line is \(\frac{3}{\sqrt{5}} \approx 1.342\) units (exactly \(\frac{3\sqrt{5}}{5}\)), and \(d^2 = \frac{9}{5} = 1.8\) units².

How to Use the Calculator

  1. Enter the x-coordinate (x₁) of your point P.
  2. Enter the y-coordinate (y₁) of your point P.
  3. Enter the Coefficient A — the number multiplying \(x\) in your line equation.
  4. Enter the Coefficient B — the number multiplying \(y\).
  5. Enter the Coefficient C — the constant term.
  6. Read the result: the shortest distance \(d\), the distance squared \(d^2\), and a step-by-step breakdown of the calculation.

If your line is given in slope-intercept form \(y = mx + b\), rewrite it first: \(mx - y + b = 0\), so \(A = m\), \(B = -1\), and \(C = b\). For a line through two points, first convert it to the form \(Ax + By + C = 0\) before entering the coefficients.

What Is the Distance from a Point to a Line?

Given a point P and an infinite straight line, there are infinitely many segments connecting P to points on the line. The shortest of these segments is the one perpendicular to the line, and its length is what we call the distance from the point to the line. This is a fundamental concept in analytic geometry with applications in computer graphics, robotics, collision detection, geographic information systems, and optimization.

The formula works for any line written in general form \(Ax + By + C = 0\). The expression \(Ax_1 + By_1 + C\) is zero exactly when the point lies on the line. When it is not zero, dividing by \(\sqrt{A^2 + B^2}\) — the length of the normal vector \((A, B)\) — converts the raw value into an actual distance, making the result independent of how the equation is scaled. Multiplying the whole equation by 2, for example, does not change the distance.

A result of 0 units means the point lies exactly on the line. Larger values simply mean the point is farther away; the distance is always non-negative because of the absolute value in the numerator. The perpendicular segment also tells you where the closest point on the line is: it is the foot of the perpendicular dropped from P.

Assumptions, Limitations and Tips

  • The line must be valid: coefficients A and B cannot both be zero; otherwise the equation does not define a line, and the calculator will show an error.
  • The line is infinite: the distance is measured to the full line, not to a segment or ray. For a segment, the closest point may be one of its endpoints.
  • Scale invariance: you may multiply A, B and C by any nonzero constant (including negative values) without changing the distance, since the formula normalizes automatically.
  • Converting from other forms: from \(y = mx + b\) use \(A = m\), \(B = -1\), \(C = b\); from two points \((x_1, y_1)\), \((x_2, y_2)\) use \(A = y_1 - y_2\), \(B = x_2 - x_1\), \(C = x_1 y_2 - x_2 y_1\).
  • Units: the distance is expressed in the same units as your coordinates, so use consistent units for both axes.

Distances between points and lines appear in many related problems. If you are rewriting line equations or solving systems that involve perpendicular lines, the Elimination Method calculator can help find intersection points, while expanding expressions such as \((A x_1 + B y_1 + C)\)-style products is quick with the FOIL method calculator or the Multiplying Binomials calculator.

Frequently Asked Questions

What if my line is vertical, like x = 5?

A vertical line fits the general form perfectly. Rewrite x = 5 as \(x - 5 = 0\), so \(A = 1\), \(B = 0\), and \(C = -5\). Then \(d = |x_1 - 5|\), which is just the horizontal gap between the point and the line. Similarly, a horizontal line \(y = 3\) becomes \(y - 3 = 0\), giving \(A = 0\), \(B = 1\), \(C = -3\).

How do I find the coordinates of the closest point on the line?

The closest point (the foot of the perpendicular) is \(F = \left(x_1 - \frac{A(Ax_1 + By_1 + C)}{A^2 + B^2},\; y_1 - \frac{B(Ax_1 + By_1 + C)}{A^2 + B^2}\right)\). Compute the value \(s = Ax_1 + By_1 + C\) first, then subtract \(\frac{A \cdot s}{A^2 + B^2}\) from \(x_1\) and \(\frac{B \cdot s}{A^2 + B^2}\) from \(y_1\). The distance from P to F equals the calculator's result.

Can the distance be negative?

No. The absolute value in the numerator guarantees \(d \ge 0\). The sign of \(Ax_1 + By_1 + C\) before taking the absolute value only tells you which side of the line the point is on — positive on one side, negative on the other — but the distance itself is always non-negative, and it equals 0 exactly when the point lies on the line.

Why is my answer wrong when I convert from y = mx + b?

The most common mistake is a sign error. For \(y = mx + b\), you must move everything to one side: \(mx - y + b = 0\), so \(B = -1\), not \(+1\). Forgetting the minus sign on B is the single most frequent error with this formula. Double-check that substituting your point and coefficients into \(Ax_1 + By_1 + C\) matches what you expect by hand.

Does this formula work for a line segment or a ray?

No — it measures distance to the infinite line extending in both directions. For a segment from \(P_1\) to \(P_2\), first find the foot of the perpendicular. If it lies between the endpoints, the perpendicular distance is correct; otherwise the answer is the shorter of the two point-to-point distances to the endpoints. For a ray, the endpoint matters only when the foot falls behind the ray's start.

What units is the result in, and how do I convert it?

The distance comes out in whatever units your coordinates use. If both axes are in meters, \(d\) is in meters. Keep units consistent: mixing feet on one axis with meters on the other gives a meaningless result. To convert the output, apply the usual factor — for example, multiply meters by 3.28084 to get feet, or divide by 1000 to get kilometers.

Is there a similar formula for 3D or for the distance between two parallel lines?

Yes. In 3D, the distance from a point to a plane \(Ax + By + Cz + D = 0\) uses \(d = \frac{|Ax_1 + By_1 + Cz_1 + D|}{\sqrt{A^2 + B^2 + C^2}}\) — the same idea with one more coordinate. For two parallel lines, pick any point on one line and compute its distance to the other using this calculator.

Leave a Reply

Your email address will not be published. Required fields are marked *