Distance between lines in $\mathbb{R}^3$R3

In space $\mathbb{R}^3$, and generally 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 defined as skew lines (skew lines). For these particular lines, a parameter of interest is their minimum distance, and consequently, the points on the two lines that represent this minimum.

Let two lines formed by points $\mathbf{x}_1$ and $\mathbf{x}_2$ have the 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.41)

where $\mathbf {p}_1$ and $\mathbf {p}_2$ are two generic 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, the unknowns of the problem.

The "distance" between two generic 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.42)

having 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 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.43)

This is a linear system in $t_1$ and $t_2$ that can be easily solved, and with this solution, one can derive the two minimum points $\mathbf {p}_1$ and $\mathbf {p}_2$.

There is also an alternative formulation to solving the linear system that arrives at the same result through purely geometric considerations. It can be demonstrated that the distance between the two lines in $\mathbb{R}^3$ is given by

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

defining $\mathbf{n} = \mathbf{v}_1 \times \mathbf{v}_2$. The vector $\mathbf{n}$, the cross product, is by definition orthogonal to both lines, and the distance is the projection of the segment $\mathbf{r}$ along that vector. It is clear that when the lines are parallel ( $\mathbf{n}=\mathbf{0}$), it is not possible to establish a reasonable value for triangulation.

The plane formed by the translation of 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.45)

Regardless of the chosen formalism, substituting these values into equations 1.41 yields the three-dimensional coordinates of the closest points between the lines.

Paolo medici
2025-10-22