Distance from a point to a line in three dimensions (source code)

= Distance from a point to a line in three dimensions
{title2=$D=|(\mathbf r_1-\mathbf r_0)\times(\mathbf r_2-\mathbf r_0)|/|\mathbf r_2-\mathbf r_1|$}

For distinct points $\mathbf r_1,\mathbf r_2$, the <cross product> in the numerator has magnitude twice the area of the <triangle> with third vertex $\mathbf r_0$. The same double area is the base length $|\mathbf r_2-\mathbf r_1|$ times the perpendicular height from $\mathbf r_0$, proving the displayed <Euclidean distance>. Equivalently, let $\mathbf u=\mathbf r_2-\mathbf r_1$ and project $\mathbf r_0-\mathbf r_1$ onto the line direction. The squared distance is $|\mathbf r_0-\mathbf r_1|^2-[\mathbf u\cdot(\mathbf r_0-\mathbf r_1)]^2/|\mathbf u|^2$; <Lagrange's identity> gives the same cross-product formula.