Point to line distance in 3D?

94 Views Asked by At

For a $3D$ straight line expressed in the standard form: $$\left\{\begin{array}{l} a_1 x + b_1 y + c_1 z + d_1 = 0\\ a_2 x + b_2 y + c_2 z + d_2 = 0\end{array}\right.$$

and a given point $(x_0,y_0,z_0)$; what is the distance from the point to the straight line?

2

There are 2 best solutions below

0
On

There are different options; here's one:

  • There is a unique plane through $(x_0,y_0,z_0)$ and perpendicular to the given line; given by: $$a(x-x_0)+b(y-y_0)+c(z-z_0)=0$$ where you can easily find $(a,b,c)$ as the cross product $(a_1,b_1,c_1)\times(a_2,b_2,c_2)$.
  • Find the point of intersection between this plane and the given line; the distance you want is then the distance between this point and $(x_0,y_0,z_0)$.
0
On

One of the other options: Find two points $\mathbf p_1$ and $\mathbf p_2$ on the line. There are various ways to do this, but a straightforward way is to convert to parametric form by finding (in homogeneous coordinates) a basis for the null space of $$\begin{bmatrix}a_1&b_1&c_1&d_1\\a_2&b_2&c_2&d_2\end{bmatrix}.$$ You can then use the formula $$d = {\|(\mathbf p_1-\mathbf p_0)\times(\mathbf p_2-\mathbf p_0)\| \over \|\mathbf p_2-\mathbf p_1\|},$$ which is the ratio of twice the area of the triangle formed by the three points to the length of its side that lies on the line.