# Distance between skew lines - correct method ?

If we have two skew lines in $\mathbb R^3$, $\vec r_{1} = \vec a + \lambda\vec d_1$ and $\vec r_{2} = \vec b + \mu\vec d_2$ then at their closest point, the difference vector $\vec r_2 - \vec r_1$ is perpendicular to both $\vec r_1$ and $\vec r_2$, so:

$(\vec r_2 - \vec r_1) \cdot \vec d_1 = 0$

$(\vec r_2 - \vec r_1) \cdot \vec d_2 = 0$

from which we have two eqns in $\lambda$ and $\mu$ which we can solve to find the required minimum $\vec r_2 - \vec r_1$.

Is this reasoning correct ?

-

Normalized vector perpendicular to both lines: $$\vec{n} = {\vec{d_1} \times \vec{d_2} \over \|\vec{d_1} \times \vec{d_2}\|}$$

shortest distance between the two lines: $$\mid{(\vec{a} - \vec{b}) \cdot \vec{n}}\mid$$

-

Yes, your reasoning is correct.

Since the difference between the closest points is perpendicular to both $\vec{d_1}$ and $\vec{d_2}$ (that is, parallel to $\vec{d_1}\times\vec{d_2}$), we get $$\vec{b} - \vec{a} = \lambda\;\vec{d_1} - \mu\;\vec{d_2} + \nu\;\vec{d_1}\times\vec{d_2}$$ Taking the dot product with $\vec{d_1}$ and $\vec{d_2}$ yields two equations in two unknowns \begin{align} (\vec{b}-\vec{a})\cdot\vec{d_1}&=\lambda\;\vec{d_1}\cdot\vec{d_1} - \mu\;\vec{d_2}\cdot\vec{d_1}\\ (\vec{b}-\vec{a})\cdot\vec{d_2}&=\lambda\;\vec{d_1}\cdot\vec{d_2} - \mu\;\vec{d_2}\cdot\vec{d_2} \end{align} As long as $\vec{d_1}$ is not parallel to $\vec{d_2}$, these equations can be solved for $\lambda$ and $\mu$.

-
perhaps I'm dimwitted, but aren't your final eqns precisely equivalent to those I wrote down ? (except that I saw no need to mention the cross product) –  ukmaths Jul 31 '11 at 10:10
@ukmaths:yes, I should have answered the stated question: your reasoning is correct. That being said, I was simply writing the equations in a form that explicitly deals with the knowns ($\vec{a}$, $\vec{b}$, $\vec{d_1}$, and $\vec{d_2}$) and the unknowns ($\lambda$ and $\mu$). I also thought it worth mentioning that if $\vec{d_1}$ and $\vec{d_2}$ are parallel, then no solution exists (which is in accord with the geometry that no closest point exists). –  robjohn Jul 31 '11 at 11:50
Right, thanks. I merely asked this question as I had to solve such a problem yesterday (not having done so for a loooong time) and thought up this method - my answers were coming out wrong (arithmetic probably), so I was wondering if there was some hole in my reasoning - a bit of Googling seems to suggest that everyone in the world apart from me starts thinking about it in terms of cross-products, which seems to me to be irrelevant with this approach (though better for the project-a-difference-vector-onto-the-common-normal method, of course) –  ukmaths Jul 31 '11 at 13:06
@j.c.: fixed. Thanks. –  robjohn Jan 30 '14 at 1:20

I would have said that the difference vector $\vec{r_2} - \vec{r_1}$ must be perpendicular to both $\vec{d_1}$ and $\vec{d_2},$ which is why it is a multiple of $\vec{d_1} \times \vec{d_2}.$

-