Skip to content
FoundationSource checked

Point-Line Distance

Computes the shortest distance from a point to a line.

Quick Facts

Compact metadata for implementation and discovery.

Category
Geometry
Difficulty
Beginner
Family
Distance Query
Tier
Foundation
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
4
Code example
Ready
Visualization
Ready

Overview

Point-line distance measures the perpendicular separation between a point and an infinite line, usually by projecting the point onto the line or using a determinant formula.

Core Concepts

perpendicular distanceprojectionline equationdegenerate line

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(1)

Average

O(1)

Worst

O(1)

Space

O(1)

When to Use

  • Use it for geometric proximity to an infinite line.
  • Use it inside collision, fitting, or distance-to-feature calculations.
  • Use segment-distance formulas instead when endpoints matter.

When Not to Use

  • Avoid it for line segments unless the projection is clamped to the segment.
  • Avoid it with a zero-length line definition.
  • Avoid exact comparisons without tolerance in floating-point geometry.

What It Does

  • Measures the perpendicular distance from a point to an infinite line
  • Uses perpendicular distance and cross product to guide the work.
  • Produces geometric relation, simplified shape, or constructed geometry.

Use Cases

  • Collision and intersection tests
  • Shape analysis
  • Geometry processing

Inputs

  • Points, segments, polygons, or meshes
  • Query shape or tolerance

Outputs

  • Geometric relation, simplified shape, or constructed geometry

Key Formulas (1)

Point-line distance

distance = |cross(b − a, p − a)| / ||b − a||
distance = |cross(b - a, p - a)| / ||b - a||

Measures perpendicular distance from a point to a line.

Pseudocode

  1. 1.Prepare the inputs and state needed for Point-Line Distance.
  2. 2.Apply the perpendicular distance step while the stopping condition has not been met.
  3. 3.Update intermediate state and discard invalid candidates.
  4. 4.Return geometric relation, simplified shape, or constructed geometry.

Canonical Example

Input
point = (0, 2), line = y = 0
Output
distance = 2
Explanation
The shortest path from the point to the x-axis is the vertical segment of length 2.

Implementation Notes

  • Represent the line consistently, such as two points or ax + by + c = 0.
  • Check for degenerate line definitions before dividing by length.
  • Use squared distances when only comparisons are needed.

Common Pitfalls

  • Using infinite-line distance when segment distance is required.
  • Failing to handle coincident line points.
  • Comparing floating-point distances for equality without tolerance.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Draw the input shapes, active tests, and generated geometric result.

Point-Line Distance mechanism walkthrough step 1 of 4
Step 1 of 4: Prepare the inputs and state needed for Point-Line Distance.
geometry-mechanism

Notes

For segments and rays, compute the projected parameter and clamp it to the allowed interval.

Sources (1)

What each reference supports for this entry.

Computational Geometry

Book

Computational geometry textbook reference for the predicates or constructions used by Point-Line Distance.

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Conceptual neighborLine Segment Intersection

Both are basic geometric predicates over points and lines.

RDP uses point-to-segment distance to decide which vertices to keep.

Tags

Computational GeometryGeometryDistance MetricLinear Algebra