[Math] Distance between a point and a line in space

euclidean-geometry

I have two points $P_1(x_1, y_1, z_1)$ and $P_2(x_2, y_2, z_2)$ on a line, $L$,
and another point $P_0(x_0, y_0, z_0)$.

I want to find the distance between $P_0$ and $L$. Could someone help?

Best Answer

The distance $h$ from the point $P_0=(x_0,y_0,z_0)$ to the line passing through $P_1=(x_1,y_1,z_1)$ and $P_2=(x_2,y_2,z_2)$ is given by $h=2A/r$, where $A$ is the area of a triangle defined by the three points and $r$ is the distance from $P_1$ to $P_2$. The values of $r$ and $A$ can be computed as follows:

$r=\sqrt{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}$ and $A=\frac{1}{2}\sqrt{a_1^2+a_2^2+a_3^2},$

where

$a_1=x_0y_1+x_1y_2+x_2y_0 - (y_0x_1+y_1x_2+y_2x_0),\\ a_2=y_0z_1+y_1z_2+y_2z_0 - (z_0y_1+z_1y_2+z_2y_0),\\ a_3=x_0z_1+x_1z_2+x_2z_0 - (z_0x_1+z_1x_2+z_2x_0).$

Related Question