v9.1.1
Menu

Point to Line Distance

easyFREEEpipolar GeometryGeometryCV: Depth Estimation

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
  • Inputs: point is the pixel (x,y)=(0,0)(x, y) = (0, 0), the origin. line holds the coefficients (a,b,c)=(1,0,5)(a, b, c) = (1, 0, 5) of ax+by+c=0ax + by + c = 0, which here reads x+5=0x + 5 = 0, i.e. the vertical line x=−5x = -5.
  • Numerator: plug the point into the line equation: 1⋅0+0⋅0+5=51 \cdot 0 + 0 \cdot 0 + 5 = 5. Its sign says which side of the line the point is on; the absolute value ∣5∣=5|5| = 5 keeps only the size.
  • Denominator: the length of the normal vector (a,b)(a, b) is 12+02=1\sqrt{1^2 + 0^2} = 1, so nothing gets rescaled.
  • Result: d=5/1=5d = 5 / 1 = 5, rounded to 4 decimal places gives 5.0, a float.
  • Check: the origin sits exactly 5 pixels right of the line x=−5x = -5.
  • Notice that scaling the coefficients, say to (2,0,10)(2, 0, 10), describes the same line: the numerator becomes 1010 and the denominator 22, so the distance stays 55. A point lying on the line would give 00.

Constraints

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

More from CV: Depth Estimation

solution.py

Test results

Sign in to run your code against the test cases.