Distance from a Point to a Line in 3D Space
In 3D geometry, the shortest distance from a point \(P\) to a line \(L\) is the length of the segment drawn from \(P\)
to the line that meets the line at a right angle. If the line is given in parametric form \(L(t)=A+t\mathbf{v}\), then \(A\) is a known
point on the line and \(\mathbf{v}\) is a direction vector. Any point on the line has the form \(A+t\mathbf{v}\), and the vector
\(\mathbf{r}=P-A\) connects the line (at \(A\)) to the point \(P\).
A very efficient distance formula comes from the geometry of the cross product. In three dimensions, the magnitude
\(\|\mathbf{r}\times\mathbf{v}\|\) equals the area of the parallelogram spanned by \(\mathbf{r}\) and \(\mathbf{v}\).
That parallelogram has base length \(\|\mathbf{v}\|\) and height equal to the perpendicular distance from \(P\) to the line direction.
Because “area = base × height,” we get:
\[
\|\mathbf{r}\times\mathbf{v}\|=\|\mathbf{v}\|\cdot d
\quad\Rightarrow\quad
d=\frac{\|\mathbf{r}\times\mathbf{v}\|}{\|\mathbf{v}\|}.
\]
This is the standard point-to-line distance formula in 3D. It works for any nonzero direction vector \(\mathbf{v}\), and it avoids solving
systems of equations directly.
Often you also want the closest point \(F\) on the line to the point \(P\). This point is the perpendicular foot
(projection of \(P\) onto the line). The idea is to choose \(t\) so that the vector from the line point to \(P\) is orthogonal to the direction
\(\mathbf{v}\). Let \(F=A+t\mathbf{v}\). The perpendicularity condition is
\[
(P-F)\cdot \mathbf{v}=0.
\]
Substitute \(F=A+t\mathbf{v}\) to get
\[
(P-A-t\mathbf{v})\cdot \mathbf{v}=0
\quad\Rightarrow\quad
(P-A)\cdot \mathbf{v} - t\,\|\mathbf{v}\|^2=0,
\]
hence
\[
t^*=\frac{(P-A)\cdot \mathbf{v}}{\|\mathbf{v}\|^2},
\qquad
F=A+t^*\mathbf{v}.
\]
Once \(F\) is found, the distance can also be computed as \(\|P-F\|\), which matches the cross-product formula (up to rounding).
If the line is given by two points \(A\) and \(B\), you can convert it into point-direction form by taking
\(\mathbf{v}=B-A\). The only invalid case is when \(A=B\), because then \(\mathbf{v}=\mathbf{0}\) and there is no unique line direction.
In applications, point-to-line distance appears in engineering and physics: for example, the shortest distance from a sensor to a wire, the clearance
from a moving object to a rail line, or the deviation of a measured 3D point from an ideal axis. This calculator visualizes the line segment, the point,
the closest point \(F\), and the perpendicular segment \(PF\), making the algebraic formulas easier to interpret geometrically.