4.4. Shortest distance problems#

We can take advantage of vector geometry to calculate the solutions to shortest distance problems.

4.4.1. Shortest distance between two points#

In \(\mathbb{R}^n\) the shortest distance, \(d\), between two points with position vectors \(\vec{p}=(p_1, p_2, \ldots, p_n)\) and \(\vec{q} = (q_1, q_2, \ldots, q_n)\) is the length of a straight line segment connecting them. If we think about this segment as of a vector, then

\[ d = \|\vec{p} - \vec{q}\| = \sqrt{\displaystyle\sum_{i=1}^n (p_i-q_i)^2}. \]

Note that \(\|\vec{p} - \vec{q}\| = \|\vec{q} - \vec{p}\|\).

4.4.2. Shortest distance between a line and a point#

To the shortest distance, \(d\), between a line \(\vec{r} = \vec{p} + t\vec{d}\) and a point with position vector \(\vec{q}\) in \(\mathbb{R}^n\) is the length of the vector \(\vec{q} - \vec{r}\) which is perpendicular to \(\vec{d}\) (Fig. 4.10).

../_images/4_line_point_distance.svg

Fig. 4.10 The shortest distance of a point \(\vec{q}\) from the line \(\vec{r} = \vec{p} + t \vec{d}\) is the length of the vector \(\vec{q} - \vec{r}\) which is perpendicular to \(\vec{d}\).#

Since \(\vec{q} - \vec{r}\) is perpendicular to \(\vec{d}\) then since the dot product between two perpendicular vectors is zero then

\[ \vec{d} \cdot (\vec{r} - \vec{q}) = 0, \]

Substituting the vector equation of a line and rearranging to make \(t\) the subject gives

\[\begin{split} \begin{align*} \vec{d} \cdot (\vec{r} - \vec{q}) &= 0 \\ \vec{d} \cdot (\vec{p} + t \vec{d} - \vec{q}) &= 0 \\ \vec{d} \cdot \vec{p} + t \vec{d} \cdot \vec{d} - \vec{d} \cdot \vec{q} &= 0 \\ \therefore t &= \frac{\vec{d} \cdot \vec{q} - \vec{d} \cdot \vec{p}}{\vec{d} \cdot \vec{d}}. \end{align*} \end{split}\]

This gives the value of the parameter \(t\) that can be used to calculate the position vector \(\vec{r}\) and therefore the shortest distance between the point \(\vec{q}\) and the line is \(\|\vec{q} - \vec{r}\|\)[1].

Theorem 4.1 (The shortest distance between a point and a line)

The shortest distance between the point with position vector \(\vec{q}\) and a line that passes through the point with position vector \(\vec{p}\) in the direction \(\vec{d}\) is \(\|\vec{q} - \vec{r}\|\) where \(\vec{r} = \vec{p} + t \vec{d}\) and

(4.3)#\[ t = \frac{\vec{d} \cdot \vec{q} - \vec{d} \cdot \vec{p}}{\vec{d} \cdot \vec{d}}. \]

Example 4.8

Find the shortest distance between the point with position vector \(\vec{q} = (2,2,2)\) and the line \((t,t-2, t+1)\).

Solution

Writing the line in the form \(\vec{r} = \vec{p} + t \vec{d}\)

\[\begin{split} \vec{r} = \begin{pmatrix} 0 \\ -2 \\ 1 \end{pmatrix} + t \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix}, \end{split}\]

so the direction vector is \(\vec{d} = (1, 1, 1)\). Using equation (4.3)

\[\begin{split} \begin{align*} t &= \frac{\vec{d} \cdot \vec{q} - \vec{d} \cdot \vec{p}}{\vec{d} \cdot \vec{d}} \\ &= \frac{ \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} \cdot \begin{pmatrix} 2 \\ 2 \\ 2 \end{pmatrix} - \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} \cdot \begin{pmatrix} 0 \\ -2 \\ 1 \end{pmatrix} }{ \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} \cdot \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} } \\ &= \frac{6 + 1}{3} = \frac{7}{3}. \end{align*} \end{split}\]

So the point on the line which is closest to \(\vec{q}\) is

\[\begin{split} \begin{align*} \vec{r} = \begin{pmatrix} 0 \\ -2 \\ 1 \end{pmatrix} + \frac{7}{3} \begin{pmatrix} 1 \\ 1 \\ 1 \end{pmatrix} = \begin{pmatrix} 7/3 \\ 1/3 \\ 10/3 \end{pmatrix}, \end{align*} \end{split}\]

and the shortest distance is \(\|\vec{q} - \vec{r}\|\) so

\[\begin{split} \begin{align*} \vec{q} - \vec{r} &= \begin{pmatrix} 2 \\ 2 \\ 2 \end{pmatrix} - \begin{pmatrix} 7/3 \\ 1/3 \\ 10/3 \end{pmatrix} = \begin{pmatrix} - 1/3 \\ 5/3 \\ -4/3 \end{pmatrix}, \\ \therefore d &= \sqrt{\left(-\frac{1}{3}\right)^2 + \left(\frac{5}{3}\right)^2 + \left( -\frac{4}{3}\right)^2} \\ &= \sqrt{\frac{14}{3}} \approx 2.16. \end{align*} \end{split}\]

4.4.3. Shortest distance between two lines#

Given two lines \(\ell_1\) and \(\ell_2\) described by \(\vec{r}_1 = \vec{p}_1 + t \vec{d}_1\) and \(\vec{r}_2 = \vec{p}_2 + t \vec{d}_2\) in \(\mathbb{R}^n\) we have three situations to consider

  • If the two lines intersect then obviously the shortest distance is obviously 0.

  • If the two lines are parallel then any point on \(\ell_1\) can gives the shortest distance between \(\ell_1\) and \(\ell_2\). Hence we simply choose a point on \(\ell_2\) and apply method for finding the distance between a point and a line.

  • If the two lines are skew then the shortest distance is the distance of the chord that is perpendicular to both \(\ell_1\) and \(\ell_2\) (Fig. 4.11).

../_images/4_line_line_distance.svg

Fig. 4.11 The shortest distance between skew lines is the distance of the chord which is perpendicular to both lines.#

If \(\vec{r}_1\) and \(\vec{r}_2\) are points on the lines \(\ell_1\) and \(\ell_2\) respectively then the chord \(\vec{r}_1 \to \vec{r}_2\) which is perpendicular to both lines has the direction vector \(\vec{n} = \vec{d}_1 \times \vec{d}_2\). If \(d\) is the distance between \(\vec{r}_1\) and \(\vec{r}_2\) then

(4.4)#\[ \vec{r}_2 - \vec{r}_1 = d \left( \frac{\vec{d}_1 \times \vec{d}_2}{\| \vec{d}_1 \times \vec{d}_2\|} \right), \]

Let \(\hat{\vec{n}} = \dfrac{\vec{d}_1 \times \vec{d}_2}{\|\vec{d}_1 \times \vec{d}_2\|}\) and substituting the equations of \(\vec{r}_1\) and \(\vec{r}_2\) equation (4.4) gives

\[\begin{split} \begin{align*} \vec{r}_2 - \vec{r}_1 &= d \hat{\vec{n}}\\ (\vec{p}_2 + t_2 \vec{d}_2) - (\vec{p}_1 + t_1 \vec{d}_1) &= d \hat{\vec{n}}\\ (\vec{p}_2 + t_2 \vec{d}_2) \cdot \hat{\vec{n}} - (\vec{p}_1 + t_1 \vec{d}_1) \cdot \hat{\vec{n}} &= d \hat{\vec{n}} \cdot \hat{\vec{n}} \\ \vec{p}_2 \cdot \hat{\vec{n}} + t_2 \vec{d}_2 \cdot \hat{\vec{n}} - \vec{p}_1 \cdot \hat{\vec{n}} - t_1 \vec{d}_1 \cdot \hat{\vec{n}} &= d \hat{\vec{n}} \cdot \hat{\vec{n}}. \end{align*} \end{split}\]

Since \(\vec{n}\) is perpendicular to both \(\ell_1\) and \(\ell_2\) then \(\vec{d}_1 \cdot \vec{n} = \vec{d}_2 \cdot \vec{n} = 0\) and \(\hat{\vec{n}} \cdot \hat{\vec{n}} = 1\) then

\[ \vec{p}_2 \cdot \hat{\vec{n}} - \vec{p}_1 \cdot \hat{\vec{n}} = d, \]

which simplifies to

\[ d = (\vec{p}_2 - \vec{p}_1) \cdot \hat{\vec{n}}. \]

Theorem 4.2 (The shortest distance between two skew lines)

The shortest distance between two skew lines \(\vec{r}_1 = \vec{p}_1 + t_1 \vec{d}_1\) and \(\vec{r}_2 = \vec{p}_2 + t_2 \vec{d}_2\) is

(4.5)#\[ d = (\vec{p}_2 - \vec{p}_1) \cdot \hat{\vec{n}}.\]

where \(\hat{\vec{n}} = \dfrac{\vec{d}_1 \times \vec{d}_2}{\|\vec{d}_1 \times \vec{d}_2\|}\).

Example 4.9

Find the shortest distance between the two skew lines \(\ell_1\) and \(\ell_2\) defined by \((t_1, 1 + 4t_1, 3 + 2 t_1)\) and \((1, 1 + 2t_2, 3 + 4t_2)\) respectively.

Solution

First, we need to identify the direction vectors \(\vec{d}_1\) and \(\vec{d}_2\). Writing \(\ell_1\) and \(\ell_2\) in the form \(\vec{r} = \vec{p} + t \vec{d}\)

\[\begin{split} \begin{align*} \vec{r}_1 &= \vec{p}_1 + t_1 \vec{d}_1 = \begin{pmatrix} 0 \\ 1 \\ 3 \end{pmatrix} + t_1 \begin{pmatrix} 1 \\ 4 \\ 2 \end{pmatrix} , \\ \vec{r}_2 &= \vec{p}_2 + t_2 \vec{d}_2 = \begin{pmatrix} 1 \\ 1 \\ 3 \end{pmatrix} + t_2 \begin{pmatrix} 0 \\ 2 \\ 4 \end{pmatrix}, \end{align*} \end{split}\]

therefore \(\vec{d}_1 = (1, 4, 2)\) and \(\vec{d}_2 = (0, 2, 4)\). Now we can calculate \(\hat{\vec{n}}\)

\[\begin{split} \begin{align*} \vec{n} &= \vec{d}_1 \times \vec{d}_2 = \begin{vmatrix} \vec{i} & \vec{j} & \vec{k} \\ 1 & 4 & 2 \\ 0 & 2 & 4 \end{vmatrix} = \begin{pmatrix} 12 \\ -4 \\ 2 \end{pmatrix}, \\ \|\vec{n}\| &= \sqrt{12^2 + (-4)^2 + 2^2} = \sqrt{164} = 2\sqrt{41}, \\ \therefore \hat{\vec{n}} &= \frac{\vec{n}}{\|\vec{n}\|} = \frac{1}{2\sqrt{41}} \begin{pmatrix} 12 \\ -4 \\ 2 \end{pmatrix} = \begin{pmatrix} 6\sqrt{41}/41 \\ -2\sqrt{41}/41 \\ \sqrt{41}/41 \end{pmatrix}. \end{align*} \end{split}\]

Note that since \(\vec{n}\) is non-zero, \(\ell_1\) and \(\ell_2\) are skew lines. Using equation (4.5)

\[\begin{split} \begin{align*} d &= (\vec{p}_2 - \vec{p}_1) \cdot \hat{\vec{n}} \\ &= \left( \begin{pmatrix} 1 \\ 1 \\ 3 \end{pmatrix} - \begin{pmatrix} 0 \\ 1 \\ 3 \end{pmatrix} \right) \cdot \begin{pmatrix} 6\sqrt{41}/41 \\ -2\sqrt{41}/41 \\ \sqrt{41}/41 \end{pmatrix} \\ &= \begin{pmatrix} 1 \\ 0 \\ 0 \end{pmatrix} \cdot \begin{pmatrix} 6\sqrt{41}/41 \\ -2\sqrt{41}/41 \\ \sqrt{41}/41 \end{pmatrix} \\ &= \frac{6 \sqrt{41}}{41}. \end{align*} \end{split}\]