Understanding distance from point to line in homogeneous coordinates

219 Views Asked by At

I would like to find the distance between A 2d point given as the homogeneous $P=(x, y, z)$, and a 2d line given as $L=(a, b, c)$.

I found an algorithm that does this, I can't figure out why it is correct, or, why the following method I propose is wrong.


The algorithm I found online is as follows:

  1. Normalize the point to $(\tilde {x}, \tilde {y}, 1)$
  2. Normalize the line to $(n_x, n_y, d_L)$ (by normalizing by the constant $\sqrt{a^2+b^2}$)
  3. $d_{PL} = (n_x, n_y, d_L) \bullet (\tilde {x}, \tilde {y}, 1)$

In Szeliski's book, on section 2.2

The following diagram

enter image description here

shows that with the above normalization, it holds that

$(n_x, n_y, d_L) = (cos(\theta), sin(\theta), d)$, with $\theta$ being the angle of the line normal as shown.


From this, we can see that equation 3 is

$d_{PL} = (cos(\theta), sin(\theta), d_L) \bullet (\tilde {x}, \tilde {y}, 1) = $

$ = \tilde {x}cos(\theta) + \tilde {y}sin(\theta) + d_L$

Which is the distance from the origin to the line $d_L$ plus some argument $A = \tilde {x}cos(\theta) + \tilde {y}sin(\theta)$ which I am not able to explain to myself.

Please explain why this algorithm works for finding the distance from a point to a line.


It seems to me the algorithm I found online is wrong, and should in fact be

  1. $d_{PL} = (n_x, n_y, 0) \bullet (\tilde {x}, \tilde {y}, 1)$

Because the line $L$ is the normal to the plane which connects $L$ with the 3d origin (since these are homogeneous coordinates).

Now, let us find the direction on the projective plane, on which the distance between the point and the line shall be measured.

That direction is

  1. Perpendicular to the line $L$
  2. On the projective plane $z=1$.

That is exactly the projection of $L=(a, b, c)$ on the projective plane $z=1$, leaving us with $(a, b, 0)$. [parallel to z].

Now all we have to do is find the projection of the point $(\tilde {x}, \tilde {y}, 1)$ (which is already on the projective plane, because of the normalization) on the direction of $(a, b, 0)$ which is $\frac{(a, b, 0)}{\sqrt{a^2+b^2}}$

That projection is $d_{PL} = \frac{(a, b, 0)}{\sqrt{a^2+b^2}} \bullet (\tilde {x}, \tilde {y}, 1) = (n_x, n_y, 0) \bullet (\tilde {x}, \tilde {y}, 1)$


Since this does not agree with what I found, I would really appreciate a review on this.


Please notice both these algorithms can't handle ideal points and the line at infinity, which leads me to an improved version:

$d_{PL} = |\frac{(a, b, c)}{\sqrt{a^2+b^2}} \bullet (\tilde{x}, \tilde{y}, 1)|_{projected-on-z=1} = |\frac{(a, b, 0)}{\sqrt{a^2+b^2}} \bullet (\tilde{x}, \tilde{y}, 1)|$

Where the last equality mustn't be computed if we refer to that 3-vector as a point, then it may be a point at infinity