How to Find the Distance Between Two Lines

As long as two lines don’t intersect, there will be one point on each line where the two lines are closest to each other. To find the distance between two lines at this point, you use the directional vectors of both lines to find another vector that is perpendicular to both lines. If you have a line $l$ along the vector ${\stackrel{\to }{r}}_{l}$ and another line $k$ along the vector ${\stackrel{\to }{r}}_{k}$, this is how you find the shortest distance between the lines:

Rule

TheDistanceBetweenTwoLines

1.
Let $P$ be a random point on the line $l$ and $Q$ be a random point on the line $k$. Express these points by using the parametric equations of the lines.
2.
Create an expression for the vector $\stackrel{\to }{PQ}$.
3.
At the point where the two lines are closest to each other, the vector $\stackrel{\to }{PQ}$ is perpendicular to both lines. This means that you want
 $\stackrel{\to }{PQ}\perp {\stackrel{\to }{r}}_{l}⇔\stackrel{\to }{PQ}\cdot {\stackrel{\to }{r}}_{l}=0$

and

 $\stackrel{\to }{PQ}\perp {\stackrel{\to }{r}}_{k}⇔\stackrel{\to }{PQ}\cdot {\stackrel{\to }{r}}_{k}=0.$
4.
You now have two equations with two unknowns, and you have a system of equations to solve.
5.
When you find values for both $s$ and $t$, you can insert those into the expression for $\stackrel{\to }{PQ}$ to find what that vector looks like at the point where the two lines are closest to each other.
6.
Finally, you can find $\phantom{\rule{-0.17em}{0ex}}|\stackrel{\to }{PQ}|$, which will be the distance between the lines.

Example 1

Find the distance between the lines

$\begin{array}{llll}\hfill l:x\phantom{\rule{-0.17em}{0ex}}\left(t\right)& =1+t,\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill y\phantom{\rule{-0.17em}{0ex}}\left(t\right)& =2t,\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill z\phantom{\rule{-0.17em}{0ex}}\left(t\right)& =1+3t\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

$\begin{array}{llll}\hfill & l:x\phantom{\rule{-0.17em}{0ex}}\left(t\right)=1+t,\phantom{\rule{1em}{0ex}}y\phantom{\rule{-0.17em}{0ex}}\left(t\right)=2t,\phantom{\rule{1em}{0ex}}z\phantom{\rule{-0.17em}{0ex}}\left(t\right)=1+3t\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

and
$\begin{array}{llll}\hfill k:x\phantom{\rule{-0.17em}{0ex}}\left(t\right)& =2+s,\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill y\phantom{\rule{-0.17em}{0ex}}\left(t\right)& =-1+s,\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill z\phantom{\rule{-0.17em}{0ex}}\left(t\right)& =1+s\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

$\begin{array}{lll}\hfill k:x\phantom{\rule{-0.17em}{0ex}}\left(s\right)=2+s,\phantom{\rule{1em}{0ex}}y\phantom{\rule{-0.17em}{0ex}}\left(s\right)=-1+s,\phantom{\rule{1em}{0ex}}z\phantom{\rule{-0.17em}{0ex}}\left(s\right)=1+s& \phantom{\rule{2em}{0ex}}& \hfill \end{array}$

1.
To begin with, you make a point $P$ by using the parametric equation of $l$ and a point $Q$ by using the parametric equation of $k$:
 $P=\phantom{\rule{-0.17em}{0ex}}\left(1+t,2t,1+3t\right)$

and

 $Q=\phantom{\rule{-0.17em}{0ex}}\left(2+s,-1+s,1+s\right).$
2.
Create $\stackrel{\to }{PQ}$:
$\begin{array}{llll}\hfill \stackrel{\to }{PQ}& =\left(2+s-\phantom{\rule{-0.17em}{0ex}}\left(1+t\right),-1+s-\phantom{\rule{-0.17em}{0ex}}\left(2t\right),\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}1+s-\phantom{\rule{-0.17em}{0ex}}\left(1+3t\right)\right)\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =\phantom{\rule{-0.17em}{0ex}}\left(1+s-t,-1+s-2t,s-3t\right).\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

$\begin{array}{llll}\hfill \stackrel{\to }{PQ}& =\phantom{\rule{-0.17em}{0ex}}\left(2+s-\phantom{\rule{-0.17em}{0ex}}\left(1+t\right),-1+s-\phantom{\rule{-0.17em}{0ex}}\left(2t\right),1+s-\phantom{\rule{-0.17em}{0ex}}\left(1+3t\right)\right)\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =\phantom{\rule{-0.17em}{0ex}}\left(1+s-t,-1+s-2t,s-3t\right).\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

3.
Find
 $\stackrel{\to }{PQ}\perp {\stackrel{\to }{r}}_{l}⇔\stackrel{\to }{PQ}\cdot {\stackrel{\to }{r}}_{l}=0$

and

 $\stackrel{\to }{PQ}\perp {\stackrel{\to }{r}}_{k}⇔\stackrel{\to }{PQ}\cdot {\stackrel{\to }{r}}_{k}=0.$

The vector ${r}_{l}$ is made up of the numbers in front of $t$ in the parametric equation of $l$, and the vector ${r}_{k}$ is made up of the numbers in front of $s$ in the parametric equation of $k$. That gives you

$\begin{array}{llll}\hfill & \phantom{\rule{-0.17em}{0ex}}\left(1+s-t,-1+s-2t,s-3t\right)\cdot \phantom{\rule{-0.17em}{0ex}}\left(1,2,3\right)\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & 1+s-t-2+2s-4t+3s-9t=0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & -1+6s-14t=0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{-0.17em}{0ex}}\left(1+s-t,-1+s-2t,s-3t\right)\cdot \phantom{\rule{-0.17em}{0ex}}\left(1,1,1\right)\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & 1+s-t-1+s-2t+s-3t=0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & 3s-6t=0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

$\begin{array}{llll}\hfill \phantom{\rule{-0.17em}{0ex}}\left(1+s-t,-1+s-2t,s-3t\right)\cdot \phantom{\rule{-0.17em}{0ex}}\left(1,2,3\right)& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill 1+s-t-2+2s-4t+3s-9t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill -1+6s-14t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill \phantom{\rule{-0.17em}{0ex}}\left(1+s-t,-1+s-2t,s-3t\right)\cdot \phantom{\rule{-0.17em}{0ex}}\left(1,1,1\right)& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill 1+s-t-1+s-2t+s-3t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill 3s-6t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

4.
Solve the system of equations:
$\begin{array}{llll}\hfill 3s-6t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill 3s& =6t\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill s& =2t\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}& \hfill \\ \hfill -1+6s-14t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & ⇓\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill -1+6\cdot 2t-14t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill -1-2t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill t& =-\frac{1}{2}\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}& \hfill \\ \hfill s& =2t\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & ⇓\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill s& =-1\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

$\begin{array}{llllllll}\hfill -1+6s-14t& =0\phantom{\rule{2em}{0ex}}& \hfill 3s-6t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}& \hfill 3s& =6t\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}& \hfill s& =2t\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill -1+6\cdot 2t-14t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill \\ \hfill -1-2t& =0\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill \\ \hfill t& =-\frac{1}{2}\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill \\ \hfill & \phantom{\rule{2em}{0ex}}& \hfill s& =2\cdot \phantom{\rule{-0.17em}{0ex}}\left(\frac{-1}{2}\right)\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}& \hfill s& =-1\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

5.
Put the values you found for $s$ and $t$ back into the expression for $\stackrel{\to }{PQ}:$
$\begin{array}{llll}\hfill \stackrel{\to }{PQ}& =\left(1+\phantom{\rule{-0.17em}{0ex}}\left(-1\right)-\phantom{\rule{-0.17em}{0ex}}\left(\frac{-1}{2}\right),\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}-1+\phantom{\rule{-0.17em}{0ex}}\left(-1\right)-2\cdot \phantom{\rule{-0.17em}{0ex}}\left(\frac{-1}{2}\right),\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & \phantom{\rule{2em}{0ex}}\phantom{\rule{-0.17em}{0ex}}\left(-1\right)-3\cdot \phantom{\rule{-0.17em}{0ex}}\left(\frac{-1}{2}\right)\right)\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =\phantom{\rule{-0.17em}{0ex}}\left(\frac{1}{2},-1,\frac{1}{2}\right).\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

$\begin{array}{llll}\hfill \stackrel{\to }{PQ}& =\phantom{\rule{-0.17em}{0ex}}\left(1+\phantom{\rule{-0.17em}{0ex}}\left(-1\right)-\phantom{\rule{-0.17em}{0ex}}\left(\frac{-1}{2}\right),-1+\phantom{\rule{-0.17em}{0ex}}\left(-1\right)-2\cdot \phantom{\rule{-0.17em}{0ex}}\left(\frac{-1}{2}\right),\phantom{\rule{-0.17em}{0ex}}\left(-1\right)-3\cdot \phantom{\rule{-0.17em}{0ex}}\left(\frac{-1}{2}\right)\right)\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =\phantom{\rule{-0.17em}{0ex}}\left(\frac{1}{2},-1,\frac{1}{2}\right).\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$

6.
Then you can finally find the length of $\stackrel{\to }{PQ}$, which is the distance between the two lines: $\begin{array}{llll}\hfill \phantom{\rule{-0.17em}{0ex}}|\stackrel{\to }{PQ}|& =\sqrt{\phantom{\rule{-0.17em}{0ex}}{\left(\frac{1}{2}\right)}^{2}+{1}^{2}+\phantom{\rule{-0.17em}{0ex}}{\left(\frac{1}{2}\right)}^{2}}\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =\sqrt{\frac{1}{4}+1+\frac{1}{4}}\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\\ \hfill & =\sqrt{\frac{3}{2}}\phantom{\rule{2em}{0ex}}& \hfill & \phantom{\rule{2em}{0ex}}\end{array}$