PIXELBANKv9.1.0
Menu

Point to Line Distance

Compute the perpendicular distance from a point to a line.

In stereo matching, we often need to verify if a candidate match lies close to the epipolar line. The distance from point (x,y)(x, y) to line ax+by+c=0ax + by + c = 0 is:

d=∣ax+by+c∣a2+b2d = \frac{|ax + by + c|}{\sqrt{a^2 + b^2}}

This is derived from the geometric formula for point-to-line distance. The numerator is the signed algebraic distance, and the denominator normalizes the line coefficients.

A small distance (< 1-2 pixels) indicates a geometrically consistent match.

Example:

Input:
point_line_distance([0, 0], [1, 0, 5])
Output:
5.0
Reasoning:

Distance from origin (0, 0) to line x + 5 = 0:

  1. Numerator: |1×0 + 0×0 + 5| = |5| = 5
  2. Denominator: sqrt(1² + 0²) = sqrt(1) = 1
  3. Distance: 5/1 = 5.0 The line is x = -5 (vertical), 5 units left of origin.

Constraints:

  • point: [x, y] pixel coordinates
  • line: [a, b, c] line coefficients where ax + by + c = 0
  • Return distance rounded to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.