# Distance of two lines in $\mathbb{R}^3$

Using vector methods show that the distance between two non parallel lines $l_1$ and $l_2$ is given by $$d=\frac{|(\overrightarrow{v}_1 - \overrightarrow{v}_2) \cdot (\overrightarrow{ a}_1 \times \overrightarrow{a}_2)|}{||\overrightarrow{a}_1 \times \overrightarrow{a}_2||}$$ where $\vec{v}_1$ and $\vec{v}_2$ are random points of $l_1$ and $l_2$ respectively, and $\vec{a}_1$ and $\vec{a}_2$ are the directions of $l_1$ and $l_2$.

HINT: We consider the plane that contains $l_1$ and is parallel to $l_2$. Show that $\frac{\vec{a}_1 \times \vec{a}_2}{\|\vec{a}_1 \times \vec{a}_2\|}$ is unit perpendicular to that plane. Then take the projection of $\vec{v}_2-\vec{v}_1$ to that perpendicular direction.

How can the plane that contains $l_1$ be parallel to $l_2$ while the line $l_1$ is non parallel to $l_2$??



EDIT:

We consider the plane that contains $l_1$ and is parallel to $l_2$. That means that the plane passes through the point $\overrightarrow{v}_1$ and has as parallel vector the vector $\overrightarrow{a}$.

To find the distance between the two lines, we have to find the distance between the points $\overrightarrow{v}_1$ and $\overrightarrow{v}_2$.

The vectors $\overrightarrow{a}_1$ and $\overrightarrow{a}_2$ produce the plane, so the vector $\overrightarrow{a}_1 \times \overrightarrow{a}_2$ is perpendicular to the plane.

So, the unit perpendicular vector to the plane is $\frac{\overrightarrow{a}_1 \times \overrightarrow{a}_2}{||\overrightarrow{a}_1 \times \overrightarrow{a}_2||}$.

A vector from the plane to the point $\overrightarrow{v}_2$ is $\overrightarrow{v}_2-\overrightarrow{v}_1$.

The distance that we are looking for the length of the projection of this vector onto the normal vector to the plane.

So, $$d=\frac{|(\overrightarrow{v}_1 - \overrightarrow{v}_2) \cdot (\overrightarrow{ a}_1 \times \overrightarrow{a}_2)|}{||\overrightarrow{a}_1 \times \overrightarrow{a}_2||}$$

Is this correct?? Could I improve something at the formulation??

• Because you can rotate the plane about the line $l_1$ until it is parallel to $l_2$ – Paul Mar 4 '15 at 15:26
• Because planes are $2$ dimensional and lines are only $1$ dimensional. – user137731 Mar 4 '15 at 15:28
• I haven't understood it yet... Could you explain it further to me?? – Mary Star Mar 4 '15 at 18:13
• Imagine the two lines intersect in 3D. A point on each line together with the intersect point define a plane containing both lines. Now translate one of the lines so they no longer cross. The translated line is not in the original plane but it is parallel to it. – Paul Mar 4 '15 at 18:59
• Take unit vector perpendicular to $l_1$ and $l_2$ from cross product. – Narasimham Mar 4 '15 at 19:56

Given two lines in ${\mathbb{R}^3}$ by:

$$\begin{gathered} X = P + r \cdot U \hfill \\ Y = Q + s \cdot V \hfill \\ \end{gathered}$$

Here we use $P,Q \in {\mathbb{R}^3}$ as "starting" points and $U,V \in {\mathbb{R}^3}$ as directions. We take the blue line for our first paramtrization and the orange one for second. Both lines have edges of the cube in common, but different ones. Blue line has bottom face and orange line has top face from the cube in common. So these planes are parallel to each other. Because lines have different directions, they aren't parallel.

We want to calculate the shortest distance of the two given lines. The distance of two arbitrary points (here the red segment) seems not to have shortest lenght. The green segment looks much better.

But what can we say about the green segment? The cube help's us to find the answer quickly: The green segment is that edge of the cube, that joines the blue line with the orange one and is perpendicular with both lines. This makes the green segment very special. But why?

There is one very good reason. From the given directions $U,V \in {\mathbb{R}^3}$ we can build the vector or cross product $U \times V$ and we know the dots from $U \times V$ with $U$ and from $U \times V$ with $V$ are zero. That is $U \times V \bot U$ and $U \times V \bot V$. This is important for our calculation. Let's go:

The red segment starts in point $X$ from the blue line and ends in point $Y$ from the orange line. We write for direction vector from $X$ towards $Y$: $$\begin{gathered} \overrightarrow {XY} = Y - X \hfill \\ \overrightarrow {XY} = s \cdot V - r \cdot U + \overrightarrow {PQ} \hfill \\ \end{gathered}$$ And of course, here $\overrightarrow {PQ} = Q - P$ is the vector which starts in $P$ and ends in $Q$.

For the green segment we use point $A$ from the blue line as starting point and $B$ from the orange line as ending point. And we write $\overrightarrow {AB} = B - A$ as usual for direction.

But, do you remember? $\overrightarrow {AB}$ has same direction as $U \times V$! We can say this more precise:

$$\overrightarrow {AB} = t \cdot U \times V$$ for a number $t \in \mathbb{R}$.

And now, we want the direction $\overrightarrow {XY}$ to be $\overrightarrow {AB}$. Well that is

$$\begin{gathered} \overrightarrow {AB} = \overrightarrow {XY} \hfill \\ \hfill \\ t \cdot U \times V = s \cdot V - r \cdot U + \overrightarrow {PQ} \hfill \\ \end{gathered}$$

Why are we doing this? We want to find that number $t \in \mathbb{R}$. And in less than a second, we are done. Applying the dot with $U \times V$ in last equation gives instantly: $$\begin{gathered} t \cdot \left( {U \times V \cdot U \times V} \right) = s \cdot \left( {V \cdot U \times V} \right) - r \cdot \left( {U \cdot U \times V} \right) + \overrightarrow {PQ} \cdot U \times V \hfill \\ \hfill \\ t \cdot {\left\| {U \times V} \right\|^2} = \overrightarrow {PQ} \cdot U \times V \hfill \\ \end{gathered}$$

because $U \cdot U \times V = V \cdot U \times V = 0$. At this point we can't calculate on without an assumption. To eliminate for $t$ we have to divide with ${\left\| {U \times V} \right\|^2}$. If the directions $U,V \in {\mathbb{R}^3}$ for our lines are linear independent, then $U \times V \ne \vec 0$ and has a length different from zero. So we get for $t$:

$$t = \frac{{\overrightarrow {PQ} \cdot U \times V}}{{{{\left\| {U \times V} \right\|}^2}}}$$

And also we get the shape for $$\overrightarrow {AB} = \frac{{\overrightarrow {PQ} \cdot U \times V}}{{{{\left\| {U \times V} \right\|}^2}}} \cdot U \times V$$

What about the length for this $\overrightarrow {AB}$? Here it is:

$$\begin{gathered} \overrightarrow {AB} \cdot \overrightarrow {AB} = {\left\| {\overrightarrow {AB} } \right\|^2} = \frac{{\overrightarrow {PQ} \cdot U \times V}}{{{{\left\| {U \times V} \right\|}^2}}} \cdot \frac{{\overrightarrow {PQ} \cdot U \times V}}{{{{\left\| {U \times V} \right\|}^2}}} \cdot {\left\| {U \times V} \right\|^2} \hfill \\ \hfill \\ {\left\| {\overrightarrow {AB} } \right\|^2} = \frac{{{{\left( {\overrightarrow {PQ} \cdot U \times V} \right)}^2}}}{{{{\left\| {U \times V} \right\|}^2}}} \hfill \\ \hfill \\ \left\| {\overrightarrow {AB} } \right\| = \frac{{\left| {\overrightarrow {PQ} \cdot U \times V} \right|}}{{\left\| {U \times V} \right\|}} \hfill \\ \end{gathered}$$

And if we re-write: $\overrightarrow {PQ} = Q - P$

$$\left\| {\overrightarrow {AB} } \right\| = \frac{{\left| {(Q - P) \cdot U \times V} \right|}}{{\left\| {U \times V} \right\|}}$$

So: Given two lines in $\phi ,\psi \subset {\mathbb{R}^3}$ with points $P,Q \in {\mathbb{R}^3}$ and directions $U,V \in {\mathbb{R}^3}$, that are of shape: $$\begin{gathered} \phi = P + r \cdot U \hfill \\ \psi = Q + s \cdot V \hfill \\ \end{gathered}$$ then, if $U$ and $V$ are linear independent, their distance is given by:

$$d(\phi ,\psi ) = \frac{{\left| {(Q - P) \cdot U \times V} \right|}}{{\left\| {U \times V} \right\|}}$$

In my opinion it's important to make a difference between points and vectors. Because points are no vectors. Points can not be added. The difference between two points is a vector. And if I add to a point a vector I get a point. In your formula I would replace "vectors" $\overrightarrow {{v_1}} ,\overrightarrow {{v_2}}$ by points, because these are points. And points didn't have overarrows.

Thank you for listening!

• Excellent figure +1 – HK Lee Apr 6 '15 at 3:42
• @HeeKwonLee Tried to make relevant points to get an idea for this problem visible. We all are living in three-dimensional space. We should know the facts. Thank you. – Frieder Apr 6 '15 at 11:26

we are looking for two pints $P_1 = v_1 + t_1\, a_1, P_2 = v_2 + t_2\, a_2$ where $t_1, t_2$ are real numbers so that $\vec{P_1P_2}$ is orthogonal to both $a_1$ and $a_2.$ in other words, $$\vec{P_1P_2} = (v_2 -t_2 a_2 )-(v_1-t_1a_1)=( v_2 - v_1) -t_2a_2 + t_1a_1= k a_1 \times a_2 \tag 1$$ taking dot product of $(1)$ with $a_1\times a_2$ gives $$(v_2 - v_1)\cdot(a_1 \times a_2) = k\, |a_1 \times a_2|^2$$ that is $$|k| = \frac{|(v_2 - v_1)\cdot(a_1 \times a_2)|}{|a_1 \times a_2|^2}$$

and the shortest distance between the lines is $$|\vec{P_1P_2}| = |k||a_1 \times a_2| = \frac{|(v_2 - v_1)\cdot(a_1 \times a_2)|}{|a_1 \times a_2|}$$ as required.

As to your hint, consider the line through the point $\overrightarrow v_1$ parallel to $l_2$. Since that line and $l_1$ both pass through the point $\overrightarrow v_1$, they determine a plane which is parallel to $l_2$.

What you actually want is the distance between this plane and the point $\overrightarrow v_2$, which will be the shortest possible distance between $l_1$ and $l_2$. A unit vector perpendicular to this plane (which you had right) is

$$\frac{\overrightarrow a_1\times\overrightarrow a_2}{\|\overrightarrow a_1\times\overrightarrow a_2\|}$$

You are also correct that the length of the projection of the vector $\overrightarrow v_2-\overrightarrow v_1$ onto this vector

$$\left|(\overrightarrow v_2-\overrightarrow v_1)\cdot\frac{\overrightarrow a_1\times\overrightarrow a_2}{\|\overrightarrow a_1\times\overrightarrow a_2\|}\right|$$ is the required distance.

(I think your only point of error is where you say, "we have to find the distance between the points $\overrightarrow v_1$ and $\overrightarrow v_2$.")

The distance between two lines is defined by $$d=\inf_{\substack{\vec w_1\in l_1\\\vec w_2\in l_2}}\|\vec w_1-\vec w_2\|.$$ This infimum is actually a minimum, which means that there are two points $\vec w_1\in l_1$ and $\vec w_2\in l_2$ such that $\|\vec w_1-\vec w_2\|=d$.

The vector $\vec a_1\times\vec a_2$ is orthogonal to both $\vec a_1$ and $\vec a_2$. We will assume in the following that $\vec a_1\times\vec a_2\neq\vec0$. In this case, the vector $\vec u=\frac{\vec a_1\times \vec a_2}{\|\vec a_1\times \vec a_2\|}$ is a unit vector.

For any $x_1\in\mathbb R$, let us consider the point $\vec r_1\in l_1$ such that $\vec r_1-\vec w_1=x_1\vec a_1$. Let us consider $$\begin{split}\|\vec r_1-\vec w_2\|^2&=\|\vec r_1-\vec w_1\|^2+\|\vec w_1-\vec w_2\|^2+2(\vec r_1-\vec w_1)\cdot(\vec w_1-\vec w_2)\\&=x_1^2+d^2+2x_1\vec a_1\cdot(\vec w_1-\vec w_2).\end{split}$$ The minimum of this function of $x_1$ must be reached at $x_1=0$ by definition of $\vec w_1$. The second order polynomial $x_1^2+d^2+2x_1\,\vec a_1\cdot(\vec w_1-\vec w_2)$ reaches its minimum at $x_1=-\vec a_1\cdot(\vec w_1-\vec w_2)$. We conclude that $\vec a_1\cdot (\vec w_1-\vec w_2)=0$, that is $\vec w_1-\vec w_2$ is orthogonal to $\vec a_1$. We can make the same reasoning and obtain that $\vec w_1-\vec w_2$ is also orthogonal to $\vec a_2$. As a conclusion, $\vec w_1-\vec w_2$ is colinear to $\vec u$.

To get the norm of $\vec w_1-\vec w_2$, since $\vec u$ is a unit vector, we can take the absolute value of the scalar product of $(\vec w_1-\vec w_2)\cdot \vec u$. Therefore $$d=\left\lvert(\vec w_1-\vec w_2)\cdot u\right\rvert.$$ In this last equation, we can replace $\vec w_1$ by $\vec v_1$ and $\vec w_2$ by $\vec v_2$ because $$\begin{split}(\vec v_1-\vec v_2)\cdot\vec u&=(\vec v_1-\vec w_1+\vec w_1-\vec w_2+\vec w_2-\vec v_2)\cdot\vec u\\ &=(\vec v_1-\vec w_1)\cdot\vec u+(\vec w_1-\vec w_2)\cdot \vec u+(\vec w_2-\vec v_2)\cdot u\\ &=0+(\vec w_1-\vec w_2)\cdot\vec u+0.\end{split}$$ We remark that $\vec r_1-\vec w_1=x_1\vec a_1$ for a certain $x_1\in\mathbb R$.

Note that we have shown a stronger result: $\vec w_1-\vec w_2=\pm d\vec u$.

If $\vec a_1\times\vec a_2=\vec0$, the lines $l_1$ and $l_2$ are either confounded or distinct and parallel. In that case, the distance between the lines id $d=\left\lvert(\vec v_1-\vec v_2)\times \vec a_1\right\rvert/\|\vec a_1\|$. Could you prove it using the same technique ?

There is a formula for the shortest distance between a plane and the origin. If that plane is expressed as a vector function: $\boldsymbol{\Pi} = \boldsymbol{\Pi}_0 + \boldsymbol{d}_1\lambda + \boldsymbol{d}_2\mu$, then the formula is $\left|\boldsymbol{\Pi}_0 \cdot \frac{\boldsymbol{d}_1 \times \boldsymbol{d}_2}{|\boldsymbol{d}_1 \times \boldsymbol{d}_2|}\right|$. Part 1 of this answer will find the shortest distance between two lines, by reducing it to finding the shortest distance between a plane and the origin. Part 2 of this answer will derive the formula for the shortest distance between a plane and the origin.

Part 1:

Given two lines:

$\boldsymbol{X} = \boldsymbol{X}_0 + \lambda \boldsymbol{X}'$

$\boldsymbol{Y} = \boldsymbol{Y}_0 + \mu \boldsymbol{Y}'$

The problem is to find the minimum value of $|\boldsymbol{X}-\boldsymbol{Y}|$. But $\boldsymbol{X}-\boldsymbol{Y}$ is the equation of a plane, and then the minimization problem is finding the shortest distance from the origin to that plane. We get that the shortest distance is $\left|(\boldsymbol{X}_0 - \boldsymbol{Y}_0)\cdot\frac{\boldsymbol{X'}\times\boldsymbol{Y'}}{|\boldsymbol{X'}\times\boldsymbol{Y'}|}\right|$. The result is proven.

Part 2 (deriving the formula for the shortest distance from origin to plane):

Let $\boldsymbol{\Pi} = \boldsymbol{\Pi}_0 + \boldsymbol{d}_1\lambda + \boldsymbol{d}_2\mu$.

The shortest distance from the origin to the plane is the perpendicular distance from the origin to the plane (why?). Let $\boldsymbol{\hat{n}}$ be the normal of the plane. The shortest distance is $\boldsymbol{\hat{n}} \cdot \boldsymbol{\Pi}_0$. And $\boldsymbol{\hat{n}} = \frac{\boldsymbol{d}_1 \times \boldsymbol{d}_2}{|\boldsymbol{d}_1 \times \boldsymbol{d}_2|}$.

This part would be clearer with a diagram.

Take two parallel planes and draw an arbitrary line in each. Both lines are parallel to both planes, but they needn't be parallel to each other.

• I got stuck right now... How can that hold?? Could you explain it further to me?? – Mary Star Mar 4 '15 at 18:12
• Take two sheets of carton and draw a line on each. – Yves Daoust Mar 4 '15 at 18:43
• I added as an anser a picture... Is that what you mean?? @YvesDaoust – Mary Star Mar 4 '15 at 19:49
• I tried to solve the exercise and added at my initial post what I have done... Could you take a look?? @YvesDaoust – Mary Star Mar 18 '15 at 18:57
• Why these downvotes ?? – Yves Daoust Apr 3 '15 at 6:44

Do you mean the following @YvesDaoust ??

• He exactly meant that. (Assuming the two planes do not intersect but are parallel) – Patrick Da Silva Mar 4 '15 at 19:52
• Yep, two parallel planes, two skew lines. – Yves Daoust Mar 4 '15 at 20:21
• Ok... I tried to solve the exercise and added at my initial post what I have done... Could you take a look?? @PatrickDaSilva – Mary Star Mar 18 '15 at 18:57
• This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – hjhjhj57 Apr 5 '15 at 21:05
• Thanks for the prompt reply @hjhjhj57. That is a distinct possibility. OTOH there is a fresh bounty by the OP here, so looks like everything is not clear yet. I will wait for a response from Mary. Sorry about the tone of my comment. It's 1:20 am here, and looks like I'm becoming crankier by the minute... – Jyrki Lahtonen Apr 5 '15 at 22:23

First, we will find a distance between a plane and a point. And we will apply.

(1) Distance $d$ between plane $P\ :\ Ax+By+Cz=D$ and a point $p$ : There exists a point $q=(x,y,z)$ in the plane : $$|p-q|=d$$

Note that $$\overrightarrow{pq}\perp P$$

Hence $$q\in \bigg\{ p+ d\frac{(A,B,C) }{|(A,B,C)|}, p- d\frac{(A,B,C) }{|(A,B,C)|}\bigg\}$$

Hence $$(A,B,C)\cdot q=D\Rightarrow d=\frac{ | D-(A,B,C)\cdot p |}{|(A,B,C)|}$$

(2) Let $V_1\in l_1,\ V_2\in l_2$ s.t. $|V_1-V_2|$ is the distance $d$ between $l_i$.

Note that $$\overrightarrow{V_1V_2}\perp l_i$$

Let $$l \ :\ \overrightarrow{V_2V_1} +l_2$$ which passes through $V_1$. So let $P$ to be a plane containing $l,\ l_1$ : Then normal to $P$ is $$\overrightarrow{a}_1 \times \overrightarrow{a}_2$$

Since $P$ contains $V_1$ so $$P\ :\ [(x,y,z) - V_1] \cdot \overrightarrow{a}_1 \times \overrightarrow{a}_2 =0$$

or $$P\ :\ [(x,y,z) - v_1] \cdot \overrightarrow{a}_1 \times \overrightarrow{a}_2 =0$$

(3) Application : $$D=v_1 \cdot \overrightarrow{a}_1 \times \overrightarrow{a}_2$$

$$(A,B,C) = \overrightarrow{a}_1 \times \overrightarrow{a}_2$$

$$p = v_2$$