Mathematics.

coordinate geometry

Distance from a Point to a Line

Analytic Geometry22 minDifficulty4 out of 10

You should know: coordinate plane

Overview

The distance from a point to a line is the length of the shortest path connecting them — which is always the perpendicular segment from the point to the line, never a slanted one. Given a line in the general form Ax + By + C = 0 and a point (x₁, y₁) not on it, a single closed-form formula computes this shortest distance directly from the coefficients and coordinates, without needing to first find the foot of the perpendicular. This formula is a two-dimensional cousin of the point-to-plane distance formula in 3D, and it underlies everything from finding the height of a triangle given its vertices to computing clearances in CAD and robotics.

Intuition

The vector ⟨A, B⟩ is normal (perpendicular) to the line Ax+By+C=0 — the same fact used for planes in 3D, one dimension down. To find how far a point is from the line, project the vector from any point on the line to P₁ onto this normal direction; the length of that projection is exactly the perpendicular distance, because the normal direction is the only direction along which distance to the line changes. The formula packages this projection into a single computation: plug the point's coordinates directly into the line's equation, take the absolute value, and divide by the normal vector's length to normalize for scale.

Formal Definition

Definition

For a line Ax + By + C = 0 and a point P₁ = (x₁, y₁), the perpendicular distance is:

d=Ax1+By1+CA2+B2d = \frac{|Ax_1 + By_1 + C|}{\sqrt{A^2+B^2}}
Point-to-line distance formula
Ax+By+C=0(general form of a line; slopeA/B if B0)Ax+By+C=0 \quad \text{(general form of a line; slope} -A/B \text{ if } B\ne 0\text{)}

The formula requires the line in this general form, not slope-intercept form

Derivation

Let Q = (x₀, y₀) be any point on the line, so Ax₀+By₀+C = 0. The vector from Q to P₁ is ⟨x₁-x₀, y₁-y₀⟩, and the normal to the line is n = ⟨A,B⟩. The distance is the magnitude of the scalar projection of QP₁ onto n:

d=nQP1n=A(x1x0)+B(y1y0)A2+B2d = \left|\frac{\mathbf{n}\cdot\overrightarrow{QP_1}}{|\mathbf{n}|}\right| = \frac{|A(x_1-x_0)+B(y_1-y_0)|}{\sqrt{A^2+B^2}}

Scalar projection of QP₁ onto the unit normal

=Ax1+By1(Ax0+By0)A2+B2=Ax1+By1+CA2+B2= \frac{|Ax_1+By_1 - (Ax_0+By_0)|}{\sqrt{A^2+B^2}} = \frac{|Ax_1+By_1+C|}{\sqrt{A^2+B^2}}

Using Ax₀+By₀ = -C since Q lies on the line

Properties

Always shortest / perpendicular

The distance from a point to a line is always measured along the perpendicular from the point to the line\text{The distance from a point to a line is always measured along the perpendicular from the point to the line}

Zero distance means on the line

d=0    Ax1+By1+C=0    (x1,y1) lies on the lined = 0 \iff Ax_1+By_1+C = 0 \iff (x_1,y_1) \text{ lies on the line}

Scale invariance

Multiplying A,B,C all by the same nonzero constant leaves d unchanged\text{Multiplying } A, B, C \text{ all by the same nonzero constant leaves } d \text{ unchanged}

Sign of the numerator

Dropping the absolute value gives a signed distance, indicating which side of the line the point lies on\text{Dropping the absolute value gives a signed distance, indicating which side of the line the point lies on}

Applications

Path-planning algorithms compute a robot's clearance from walls or boundaries (modeled as line segments) using this formula to enforce safety margins.

Worked Examples

  1. Identify A=3, B=-4, C=1, and substitute the point's coordinates.

    Ax1+By1+C=3(2)4(5)+1=620+1=13Ax_1+By_1+C = 3(2) - 4(5) + 1 = 6-20+1 = -13
  2. Take the absolute value and divide by √(A²+B²).

    d=1332+(4)2=139+16=1325=135d = \frac{|-13|}{\sqrt{3^2+(-4)^2}} = \frac{13}{\sqrt{9+16}} = \frac{13}{\sqrt{25}} = \frac{13}{5}

Answer: d = 13/5 = 2.6

Practice Problems

Difficulty 3/10

Find the distance from the point (1, -2) to the line 5x + 12y - 3 = 0.

Difficulty 5/10

Find the distance from (4, 4) to the line 5x + 12y - 3 = 0, and check whether the point lies on the same side of the line as the origin.

Difficulty 6/10

Triangle ABC has A=(0,0), B=(6,0), C=(2,4). Using AB as the base (lying on the x-axis, i.e. the line y=0), find the triangle's area via the height from C.

Common Mistakes

Common Mistake

Applying the formula d=|Ax₁+By₁+C|/√(A²+B²) using a line given in slope-intercept form y=mx+b without first converting to general form.

The formula requires the line written as Ax+By+C=0. Convert y=mx+b to mx - y + b = 0 (so A=m, B=-1, C=b) before substituting, or the coefficients A, B, C will be wrong.

Common Mistake

Forgetting the absolute value and reporting a negative distance.

Distance is always non-negative; the absolute value in the numerator is essential. Without it, the signed value is still useful (its sign indicates which side of the line the point is on), but it isn't the distance itself.

Quiz

The distance from a point to a line is measured along:
In d = |Ax₁+By₁+C| / √(A²+B²), the vector ⟨A, B⟩ represents:
If Ax₁+By₁+C = 0 for a point (x₁,y₁) and line Ax+By+C=0, then:

Summary

  • The distance from point (x₁,y₁) to line Ax+By+C=0 is d = |Ax₁+By₁+C| / √(A²+B²).
  • This distance is always measured along the perpendicular from the point to the line — the shortest possible path.
  • The formula comes from projecting a vector to the point onto the line's normal vector ⟨A,B⟩.
  • Dropping the absolute value gives a signed distance useful for determining which side of the line a point lies on.

References