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

In space $\mathbb{R}^3$, and in general in all higher-dimensional spaces, two lines $\mathbf{l}_1$ and $\mathbf{l}_2$ may not intersect at any point even if they are not parallel. Such lines are called skew lines. For these particular lines, a quantity of interest is 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 two arbitrary points belonging to the lines, $\mathbf{v}_1$ and $\mathbf{v}_2$ are the direction vectors, and $t_1,t_2 \in \mathbb{R}$ are scalar values that are unknowns of the problem.

The “distance” between two 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 $\mathbf{r} = \mathbf{p}_2 - \mathbf{p}_1$ has been defined. The quantity to be minimized is $\Vert \mathbf{d} \Vert^2$, a function of $t_1$ and $t_2$, whose gradient vanishes at
\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 can be solved easily; using this solution, the two closest points $\mathbf {p}_1$ and $\mathbf {p}_2$ can be obtained.

There is also an alternative to solving the linear system that reaches the same result through purely geometric considerations. 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 $\mathbf{n} = \mathbf{v}_1 \times \mathbf{v}_2$ has been defined. The vector $\mathbf{n}$, obtained by the cross product, is by definition orthogonal to both lines, and the distance is the projection of the segment $\mathbf{r}$ along this vector. It is clear that when the lines are parallel ( $\mathbf{n}=\mathbf{0}$), it is not possible to determine a meaningful triangulation value.

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 chosen formalism, substituting these values into equations 1.77 yields the three-dimensional coordinates of the closest points on the lines.

Paolo medici
2026-10-01