# Shortest Distance between Two Parallel Lines in 3D

On Wikipedia, I found the following explanation for the distance between two skew lines:

According to me, the logic of the formula should work for parallel lines too. I was trying to tweak the formula (specifically, the unit vector n) to determine the distance between two parallel lines in 3D. As explained there, since we cannot use the cross product of the direction vectors of the parallel lines to find n, I tried to find n using the dot product (x, y, z) · b (or d) = 0, and found values of x, y and z which satisfied the equation. I then substituted n in the formula for d given at the end. However, I always get answers different from those that are found using other formulae (like those on http://goo.gl/4DTDdq or https://goo.gl/WrVGh6).

So, I wanted to know whether I am doing something wrong in determining n. According to me, I should be able to use the same formula (after changing n accordingly for parallel lines) — it makes sense to me geometrically — but it always gives me a different answer.

• Could you explain in more detail how you find $\mathbb{n}$ for parallel lines? The method you outlined could give a vector not lying in the plane of the two lines. Commented Sep 25, 2015 at 14:31
• Oh! So, for parallel lines, $\mathbb{n}$ should lie in the plane containing the lines. That makes sense! But, in the formula given here (goo.gl/WrVGh6), the cross product will give a vector that is perpendicular to the plane containing ($\mathbb{c}$ − $\mathbb{a}$) and $\mathbb{d}$. So why does that formula work then? Commented Sep 25, 2015 at 15:11
• Let $\theta$ be the angle between $\mathbf{c}-\mathbf{a}$ and $\mathbf{b}$, then you have $|(\mathbf{c}-\mathbf{a})\times\mathbf{b}|=|\mathbf{c}-\mathbf{a}||\mathbf{b}| \sin\theta$. But the distance between the two lines is just $|\mathbf{c}-\mathbf{a}| \sin\theta$, so that formula holds. Commented Sep 25, 2015 at 16:10
• See also my edited answer. Commented Sep 25, 2015 at 16:25

## 2 Answers

You can obtain a vector perpendicular to the given parallel lines and lying in the same plane by the product $\mathbf{b}\times((\mathbf{c}-\mathbf{a})\times\mathbf{b})$. Of course to get a unit vector $\mathbf{n}$ you must divide that by its length. So in the end one obtains: $$d={\mathbf{b}\times((\mathbf{c}-\mathbf{a})\times\mathbf{b}) \over |\mathbf{b}\times((\mathbf{c}-\mathbf{a})\times\mathbf{b})|} \cdot(\mathbf{c}-\mathbf{a})= {|(\mathbf{c}-\mathbf{a})\times\mathbf{b}|^2 \over |\mathbf{b}|\ |(\mathbf{c}-\mathbf{a})\times\mathbf{b}|}= {|(\mathbf{c}-\mathbf{a})\times\mathbf{b}| \over |\mathbf{b}|},$$ where I used the well known identity $(\mathbf{x}\times\mathbf{y})\cdot\mathbf{z}=(\mathbf{z}\times\mathbf{x})\cdot\mathbf{y}$ and in the denominator I took into account that the length of the cross product of two perpendicular vectors is equal to the product of their lengths.

• Oh! So, for parallel lines, $\mathbf{n}$ should lie in the plane containing the lines. That makes sense! But, in the formula given here (goo.gl/WrVGh6), the cross product will give a vector that is perpendicular to the plane containing ($\mathbf{c}$ − $\mathbf{a}$) and $\mathbf{d}$. So why does that formula work then? Commented Sep 25, 2015 at 15:20
• See my edited answer. Commented Sep 25, 2015 at 16:23

Two parallel lines have the same direction vector and differ only in the anchor point, i.e.,

$$L_1 :~ r_1(t) = c_1 + t v, \quad L_2 :~r_2(\lambda) = c_2 + \lambda v, \quad \lambda,t \in \mathbb{R}$$

Therefore, the distance between them at $(t,\lambda)$ is $\|r_1(t) - r_2(\lambda)\| = \|c_1 - c_2 + (t-\lambda)v\|$. Letting $\alpha = t-\lambda$, you can minimize $\|d - \alpha v\|^2$ over $\mathbb{R}$, where $d = c_1 - c_2$. The global minimum occurs at $\alpha = -d^Tv/(v^Tv)$ and it follows that the minimum distance is

$$\frac{1}{\|v\|}\left(\|d\|^2\|v\|^2 - (d^Tv)^2\right)^{1/2} = \left(\|d\|^2 - (d^T\bar{v})^2\right)^{1/2},$$

where $\bar{v} = v/\|v\|$.