Skip to main content
Home / Orthogonality / Distance Point Line

Orthogonality

Orthogonal projections, bases, and distances

💡 Need Help?

  • • Enter fractions like 1/2
  • • Use decimals like 0.5
  • • Click "Load Example" to try a preset
  • • Click any step to copy LaTeX
Calculating...

Distance Point Line Calculator

Find the shortest perpendicular distance from a point to a line, with the closest point on the line and a complete step-by-step explanation.

D Space

Point P

Line Point A

Direction v

Direction vector cannot be zero

Formula

d = ‖(P - A) - projv(P - A)‖

The distance is the magnitude of the perpendicular component.


What is the Distance from a Point to a Line?

The shortest distance from a point to a line is the length of the perpendicular segment connecting the point to the line. This is one of the most fundamental geometric measurements, appearing everywhere from computer graphics to robotics.

Core Concept: The distance from a point P to a line L is the length of the perpendicular from P to L. This is the minimum possible distance between P and any point on the line.

Simple Analogy: If you're standing next to a straight road, the shortest path to reach the road is to walk perpendicularly toward it — not at an angle. That perpendicular distance is exactly what we calculate here.


The Formula

For a Line Defined by a Point and Direction Vector

Let the line be defined by a point Q (any point on the line) and a direction vector v. Then the distance from point P to the line is:

$$ \boxed{d = \frac{\|\overrightarrow{QP} \times \mathbf{v}\|}{\|\mathbf{v}\|}} $$

Where:

  • Q = any point on the line
  • v = direction vector of the line
  • P = the point we're measuring from
  • × = cross product (in 2D and 3D)
  • ‖ ‖ = magnitude (length) of the vector

For a Line in 2D (Standard Form)

If the line is given as ax + by + c = 0, the distance from point (x₀, y₀) is:

$$ \boxed{d = \frac{|ax_0 + by_0 + c|}{\sqrt{a^2 + b^2}}} $$

Finding the Closest Point

The closest point R on the line to point P is given by:

$$ \mathbf{R} = \mathbf{Q} + \frac{(\mathbf{P} - \mathbf{Q}) \cdot \mathbf{v}}{\|\mathbf{v}\|^2} \mathbf{v} $$

This is the orthogonal projection of P onto the line.

💡 Key Insight: The vector from the closest point R to P is perpendicular to the direction vector v. This perpendicular relationship is what makes it the shortest distance.


Step-by-Step Calculation

Follow these steps to compute the distance from a point to a line:

Method 1: Using a Point and Direction Vector (Works in Any Dimension)

  1. Identify a point Q on the line and the direction vector v
  2. Compute the vector from Q to P: w = P - Q
  3. Compute the projection of w onto v: proj = (w·v / v·v) · v
  4. Find the perpendicular component: w_perp = w - proj
  5. The distance is the magnitude of the perpendicular component: d = ‖w_perp‖

Method 2: Using the Perpendicular Distance Formula (2D Only)

  1. Write the line in standard form: ax + by + c = 0
  2. Plug the point coordinates into |ax₀ + by₀ + c|
  3. Divide by √(a² + b²)
  4. The result is the perpendicular distance

📐 Note: The calculator above handles both 2D and 3D cases automatically. It also finds the closest point on the line to your point.


Geometric Interpretation

In 2D (Plane)

  • The distance is the length of the perpendicular from the point to the line
  • The closest point is where the perpendicular meets the line
  • If the point lies exactly on the line, the distance is zero
  • Think of dropping a "plumb line" straight down to the line

In 3D (Space)

  • The same formula works! The distance is still the perpendicular length
  • The closest point is the orthogonal projection onto the line
  • The vector from the point to the line is perpendicular to the line's direction
  • This works in any dimension (2D, 3D, 4D, ...)

Visual Intuition: Imagine a line stretching infinitely in both directions. The shortest path from any point to that line is always perpendicular to the line — like dropping a ball straight down to the line, not rolling it at an angle.


Complete Examples

Example 1: 2D Point to Line (Standard Form)

Problem: Find the distance from point P = (3, 4) to the line 2x + y - 5 = 0

Step 1: Identify a, b, c from the line equation

$$ a = 2,\quad b = 1,\quad c = -5 $$

Step 2: Plug into the distance formula

$$ d = \frac{|2(3) + 1(4) - 5|}{\sqrt{2^2 + 1^2}} = \frac{|6 + 4 - 5|}{\sqrt{4 + 1}} = \frac{|5|}{\sqrt{5}} = \frac{5}{\sqrt{5}} = \sqrt{5} \approx 2.236 $$

Solution: The distance is √5 ≈ 2.236 units.

Example 2: 3D Point to Line

Problem: Find the distance from point P = (1, 2, 3) to the line through Q = (0, 0, 0) with direction v = (1, 1, 1)

Step 1: Compute vector from Q to P

$$ \mathbf{w} = P - Q = (1, 2, 3) $$

Step 2: Compute the cross product w × v

$$ \mathbf{w} \times \mathbf{v} = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ 1 & 2 & 3 \\ 1 & 1 & 1 \end{vmatrix} = (2\cdot1 - 3\cdot1)\mathbf{i} - (1\cdot1 - 3\cdot1)\mathbf{j} + (1\cdot1 - 2\cdot1)\mathbf{k} = (-1, 2, -1) $$

Step 3: Compute magnitudes

$$ \|\mathbf{w} \times \mathbf{v}\| = \sqrt{(-1)^2 + 2^2 + (-1)^2} = \sqrt{1 + 4 + 1} = \sqrt{6} $$ $$ \|\mathbf{v}\| = \sqrt{1^2 + 1^2 + 1^2} = \sqrt{3} $$

Step 4: Apply the formula

$$ d = \frac{\|\mathbf{w} \times \mathbf{v}\|}{\|\mathbf{v}\|} = \frac{\sqrt{6}}{\sqrt{3}} = \sqrt{2} \approx 1.414 $$

Solution: The distance is √2 ≈ 1.414 units.

Step 5 (Optional): Find the closest point

$$ \text{projection} = \frac{\mathbf{w} \cdot \mathbf{v}}{\|\mathbf{v}\|^2} \mathbf{v} = \frac{1+2+3}{3}(1,1,1) = \frac{6}{3}(1,1,1) = (2,2,2) $$ $$ R = Q + \text{projection} = (0,0,0) + (2,2,2) = (2,2,2) $$

Example 3: Point Lies on the Line

Problem: Find the distance from P = (2, 3) to the line x - y + 1 = 0

$$ d = \frac{|2 - 3 + 1|}{\sqrt{1^2 + (-1)^2}} = \frac{|0|}{\sqrt{2}} = 0 $$

Solution: Distance = 0. The point lies directly on the line!


Special Cases

Case Condition Distance
Point on line Point satisfies line equation 0 (by definition)
Zero direction vector v = (0,0,0) (degenerate line) Undefined (not a valid line)
Line in 2D, point far away Large coordinates Proportionally large distance
Parallel lines (distance between) Two lines with same direction Use point from one line to the other

⚠️ Important: The distance is always non-negative. A distance of zero means the point lies exactly on the line.


Real-World Applications

🗺️ Navigation & GPS

Calculating how far a vehicle is from a planned route (line). Used in lane departure warnings and route deviation detection.

🎮 Computer Graphics

Ray tracing, collision detection, and determining if a point is near a line or edge.

🤖 Robotics

Path planning - how far is the robot from its desired path? Used in autonomous navigation.

📐 CAD/Engineering

Measuring tolerances - how far is a manufactured part from the designed line?

🛰️ Geodesy

Distance from a point to a line of longitude or latitude on the Earth's surface (approximated).

📊 Statistics

Distance from data points to a regression line (residuals). Used in least squares fitting.


Frequently Asked Questions

Q: Why is the perpendicular distance the shortest?

A: By the Pythagorean theorem, any non-perpendicular path forms a right triangle with the perpendicular as one leg and the slanted path as the hypotenuse, which is always longer.

Q: Does this formula work in 2D and 3D?

A: Yes! The cross product formula works in 3D. In 2D, you can use either the cross product method (treating vectors as 3D with z=0) or the simpler |ax₀+by₀+c|/√(a²+b²) formula.

Q: What if the line is given by two points instead of a point and direction?

A: The direction vector v is simply the difference between the two points. Any point on the line works as Q (use either point).

Q: Can a point have negative distance to a line?

A: No. Distance is always non-negative. The signed distance (with sign indicating which side of the line) can be negative, but geometric distance is always ≥ 0.

Q: How do I find the closest point on the line?

A: Use the projection formula: R = Q + ((P-Q)·v / ‖v‖²) · v. The calculator above computes this automatically!


Practice Problems

Beginner

  1. Find the distance from (0,0) to the line 3x + 4y - 5 = 0
  2. Find the distance from (2, -1) to the line x - 2y + 3 = 0
  3. Point (3,4) to line through (0,0) with direction (1,2)

Intermediate

  1. Find the distance from (1,2,3) to the line through (0,0,0) with direction (2, -1, 2)
  2. Find the closest point on the line to P in problem #3
  3. Two points A(1,1) and B(4,5) define a line. Find distance from P(0,0) to line AB.
Click to reveal solutions

1. d = |0+0-5|/5 = 5/5 = 1

2. d = |2 -2(-1)+3|/√(1+4) = |2+2+3|/√5 = 7/√5 ≈ 3.130

3. d = |(3,4) × (1,2)|/√(1+4) = |3·2 - 4·1|/√5 = |6-4|/√5 = 2/√5 ≈ 0.894

4. d = ‖(1,2,3) × (2,-1,2)‖/‖(2,-1,2)‖ = ‖(7,4,-5)‖/3 = √(49+16+25)/3 = √90/3 ≈ 3.162

5. R = ((3,4)·(1,2)/(1+4))·(1,2) = ((3+8)/5)·(1,2) = (11/5)·(1,2) = (2.2, 4.4)

6. Direction v = (3,4), w = (1,1), d = |1·4 - 1·3|/5 = |4-3|/5 = 1/5 = 0.2



Summary

🎯 Key Takeaways

  • Distance = ‖(P-Q) × v‖ / ‖v‖ (works in any dimension)
  • In 2D: d = |ax₀ + by₀ + c| / √(a² + b²)
  • Closest point: Orthogonal projection of P onto the line
  • Distance = 0 means the point lies exactly on the line
  • The perpendicular path is always the shortest distance

💡 Pro Tip: Use the calculator above to check your work! Enter any point and line, and it will show you the distance, closest point, and visualize the perpendicular relationship.

Try It Yourself!

Use the calculator above to find distances from points to lines:

  1. Enter your point coordinates (2D or 3D)
  2. Define your line using a point and direction vector, or using standard form coefficients
  3. Click "Calculate" to see:
    • The perpendicular distance
    • The closest point on the line
    • Step-by-step calculation
    • Geometric verification

Test these examples:

  • 2D: Point (3,4) to line 2x + y = 5
  • 3D: Point (1,2,3) to line through (0,0,0) direction (1,1,1)
  • Point on line: (2,3) to line x - y + 1 = 0 (should be 0!)

📐 Mathematical Fact: The shortest distance problem is equivalent to finding the minimum of ‖P - (Q + t·v)‖² over all real t. The solution occurs exactly when the derivative is zero, giving the projection formula!