Distance Between Lines in $\mathbb{R}^3$R3

In space $\mathbb{R}^3$, and generally in spaces of higher dimension, two lines $\mathbf{l}_1$ and $\mathbf{l}_2$ may not intersect, even if they are not parallel. Such lines are called skew lines. For these lines, quantities of interest include their minimum distance and, consequently, the points on the two lines that realize this minimum.

Consider two lines consisting of points $\mathbf{x}_1$ and $\mathbf{x}_2$, with equations

\begin{displaymath}
\begin{array}{l}
\mathbf{x}_1 = \mathbf{p}_1 + t_1 \mathbf...
...\mathbf{x}_2 = \mathbf{p}_2 + t_2 \mathbf{v}_2 \\
\end{array}\end{displaymath} (1.77)

where $\mathbf {p}_1$ and $\mathbf {p}_2$ are arbitrary points on the lines, $\mathbf{v}_1$ and $\mathbf{v}_2$ are their direction vectors, and $t_1,t_2 \in \mathbb{R}$ are scalar unknowns.

The “distance” between arbitrary points on the two lines is

\begin{displaymath}
\mathbf{d} = \mathbf{x}_2 - \mathbf{x}_1 = ( \mathbf{p}_2 +...
...athbf{v}_1) = \mathbf{r} + t_2 \mathbf{v}_2 - t_1 \mathbf{v}_1
\end{displaymath} (1.78)

where we have defined $\mathbf{r} = \mathbf{p}_2 - \mathbf{p}_1$. The quantity to minimize is $\Vert \mathbf{d} \Vert^2$, a function of $t_1$ and $t_2$, whose gradient vanishes when
\begin{displaymath}
\begin{array}{l}
\mathbf{v}_1 \cdot \mathbf{v}_1 t_1 - \mat...
...mathbf{v}_2 t_2 = \mathbf{v}_2 \cdot \mathbf{r} \\
\end{array}\end{displaymath} (1.79)

This is a linear system in $t_1$ and $t_2$ that is easy to solve. The resulting solution gives the two points of minimum distance, $\mathbf {p}_1$ and $\mathbf {p}_2$.

An alternative to solving the linear system is to arrive at the same result using purely geometric arguments. It can be shown that the distance between the two lines in $\mathbb{R}^3$ is

\begin{displaymath}
d = \frac{ \vert \mathbf{r} \cdot \mathbf{n} \vert }{\Vert \mathbf{n} \Vert }
\end{displaymath} (1.80)

where we have defined $\mathbf{n} = \mathbf{v}_1 \times \mathbf{v}_2$. By definition, the cross-product vector $\mathbf{n}$ is orthogonal to both lines, and the distance is the projection of the segment $\mathbf{r}$ onto this vector. When the lines are parallel ( $\mathbf{n}=\mathbf{0}$), no reasonable value for triangulation can be determined.

The plane formed by translating the second line along $\mathbf{n}$ intersects the first line at the point of minimum distance:

\begin{displaymath}
\begin{array}{l}
t_1 = \frac{\mathbf{r} \cdot \mathbf{v}_2...
...hbf{v}_2 \cdot \mathbf{v}_1 \times \mathbf{n} }\\
\end{array}\end{displaymath} (1.81)

Regardless of the formalism used, substituting these values into Equations 1.77 yields the three-dimensional coordinates of the closest points on the lines.

Paolo medici
2026-10-19