[Math] Point to line distance in 3D using cross product

3dparametric

I am trying to figure out the distance of point to line in 3D using parametric equations.

By setting z0 = 0 and z1 = 1, the parametric equation of the line is
v1(x0+x1*t, y0+y1*t,t).Point P has coordinates of (xx, yy, zz). Some point on the line has coordinates v0 = (x0,y0,0).

The distance should then be D = ||(v0-P)x(v0-v1)||/||(v0-v1)||.
The numerator is the area of the parallelogram, and the denominator is the base –> giving the height of the parallelogram and thus distance.

I am unsure on the meaning of v0-v1, this is a line segment? Should it be normalized before? For some reason I seem to get the correct result for D = ||(v0-P)x(v0-v1)||.

Best Answer

You have a parametric equation for a line, $$\vec{v}(t) = \vec{v}_0 + t \vec{v}_1 \tag{1}\label{1}$$ to find the minimum distance $d$ between point $\vec{p}$ and line $\vec{v}(t)$, we apply the formula shown in the Wolfram Mathworld Point-Line Distance (3D) article, noting that in this case, $\mathbf{x}_0 = \vec{p}$, $\mathbf{x}_1 = \vec{v}_0$, and $\mathbf{x}_2 = \vec{v}_0 + \vec{v}_1$ so $\mathbf{x}_2 - \mathbf{x}_1 = \vec{v}_1$: $$d = \frac{ \left\lVert \vec{v}_1 \times ( \vec{v}_0 - \vec{p} ) \right \rVert }{ \left\lVert \vec{v}_1 \right\rVert } \tag{2}\label{2}$$

The value of $t$ where the line is closest to point $\vec{p}$ is $$t = \frac{\vec{v}_1 \cdot ( \vec{p} - \vec{v}_0 )}{\vec{v}_1 \cdot \vec{v}_1} \tag{3}\label{3}$$

It is very often useful to parametrise the line with $\left\lVert \vec{v}_1 \right\rVert = 1$, because then $t$ is unscaled length. In that case, $\eqref{2}$ simplifies to $d = \left\lVert \vec{v}_1 \times \left ( \vec{v}_0 - \vec{p} \right ) \right \rVert$, and $\eqref{3}$ simplifies to $t = \vec{v}_1 \cdot ( \vec{p} - \vec{v}_0 )$.