I am tasked to find the distance between these two lines.

$p1 ... x = 1 + t, y = -1 + 2t, z = t$

$p2 ... x = 1 - t; y = 3 - t; z = t$

Those two lines are nonparallel and they do not intersect (I checked that).

Using the vector product I computed the normal (the line orthogonal to both of these lines), and the normal is $(3, -2, 1)$. Now I have the direction vector of the line which will intersect both of my nonparallel lines.

However, here's where I encounter the problem - I don't know what next. The next logical step in my opinion would be to find a point on $p1$ where I could draw that orthogonal line and where that orthogonal line would also intersect with $p2$... There's only one such point, since we are in 3D space and I could draw an orthogonal line from any point in $p1$ but it could miss $p2$.

  • $\begingroup$ The normal vector $(3, -2, 1)$ gives you a pair of parallel planes both normal to it, one contains $p1$ and one contains $p2$. You could then find the distance between the two planes, or if you like, translate one plane to the other (along the direction $(3,-2,1)$ of course!), find the point of intersection of the two lines, and use that to measure. $\endgroup$ – Elizabeth S. Q. Goodman Apr 5 '17 at 7:43
  • 1
  • $\begingroup$ @Arby If I use the formula from Wikipedia, I get that $d = 4$, since $\vec n$ is $(3, -2, 1)$, $c$ is $(1, 3, 0)$ (the second lines point) and $(1, -1, 0)$ is the first lines point. Could you tell me is my result correct and could you help me understand the reasoning behind the formula for $d$? $\endgroup$ – NumberSymphony Apr 5 '17 at 14:40
  • $\begingroup$ @NumberSymphony 4? No, the result seems to be different... $\endgroup$ – Widawensen Jan 15 '18 at 18:11
  • $\begingroup$ Read this paper that has an excellent description of 3D line geometry using Plücker coordinates. Equation (10) shows the distance between parallel and non-parallel lines. $\endgroup$ – ja72 Jan 16 '18 at 13:31

Take the common normal direction.

$$\mathbf{n} = \pmatrix{1\\2\\1} \times \pmatrix{-1\\-1\\1} = \pmatrix{3 \\-2 \\1 } $$

Now project any point from the lines onto this direction. Their difference is the distance between the lines

$$ d = \frac{ \mathbf{n} \cdot ( \mathbf{r}_1 - \mathbf{r}_2 )}{\| \mathbf{n} \|} $$

$$ d = \frac{ \pmatrix{3\\-2\\1} \cdot \left( \pmatrix{1\\-1\\0} - \pmatrix{1\\2\\1} \right) }{ \| \pmatrix{3\\-2\\1} \|} = \frac{ \pmatrix{3\\-2\\1} \cdot \pmatrix{0\\-4\\0} } {\sqrt{14}} = \frac{8}{\sqrt{14}} = 2.1380899352993950$$

NOTE: The $\cdot$ is the vector inner product, and $\times$ is the cross product

  • $\begingroup$ Some additional remark ( more for me) ... $ \dfrac{n}{\Vert n \Vert} \dfrac{n^T}{\Vert n \Vert}r_1-\dfrac{n}{\Vert n \Vert} \dfrac{n^T}{\Vert n \Vert}r_2$ $\endgroup$ – Widawensen Jan 15 '18 at 17:45
  • $\begingroup$ Concluding remark: your method is simpler (+1) but mine however has also some advantages: potentially gives more additional information.. $\endgroup$ – Widawensen Jan 15 '18 at 17:50
  • $\begingroup$ @Widawensen - for you $$d = \frac{ \mathbf{n}^\top \mathbf{r}_1 - \mathbf{n}^\top \mathbf{r}_2 }{\| \mathbf{n} \|}$$ $\endgroup$ – ja72 Jan 15 '18 at 19:46
  • $\begingroup$ What was important in the given above formula by me that it leads to the explanation why it has such form (what was once also asked by OP) After some deliberation the full starting formula for the vector $p$ which is a difference of projections on the normal $n$ (translated by vector $a$ in such a way that now normal is passing point $(0,0,0)$) should be $p= \dfrac {n}{\Vert n \Vert} \dfrac {n^T}{\Vert n \Vert}(r_1+a)-\dfrac {n}{\Vert n \Vert} \dfrac {n^T}{\Vert n \Vert}(r_2+a)$. This leads to the formula written by you. $\endgroup$ – Widawensen Jan 16 '18 at 10:10

HINT...find any vector joining one point on one line to another point on the other line and calculate the projection of this vector onto the common normal which you have found already.


Lines can be written in a vector form:

$p_1=\begin{bmatrix} 1 \\ -1 \\ 0 \end{bmatrix}+t\begin{bmatrix} 1 \\ 2 \\ 1 \end{bmatrix} $

$p_2=\begin{bmatrix} 1 \\ 3 \\ 0 \end{bmatrix}+s\begin{bmatrix} -1 \\ -1 \\ 1 \end{bmatrix} $

Denote it with symbols of vectors $p_{01},p_{02},v_1,v_2$:


Distance is measured alongside vector which is perpendicular to $v_1$ and $v_2$, we can take for example a cross product $v_\perp=v_1 \times v_2$ what you have already done.

Now moving from the point $p_{01}$ to the point $p_{02}$ through $p_{1\perp}$ and $p_{2\perp}$ where $p_{1\perp},p_{2\perp}$ are the ends of segment perpendicular to the lines $p_1$ and $p_2$ we have:

$p_{12}=p_{02}-p_{01}= t v_1+r v_\perp+s v_2 = \begin{bmatrix} v_1 & v_\perp & v_2 \end{bmatrix} \begin{bmatrix} t \\ r \\ s \end{bmatrix} $

Solution for this equation is:

$\begin{bmatrix}t \\ r \\ s \end{bmatrix}=\begin{bmatrix} v_1 & v_\perp & v_2 \end{bmatrix} ^{-1}p_{12} $

Having $t , r, s $ it's straightforward to calculate the ends of segment perpendicular to both lines and its length $d=\Vert rv_\perp \Vert$.

  • $\begingroup$ Computations at Wolphram Alpha inverse{{1,3,-1},{2,-2,-1},{1,1,1}}*{{0},{-4},{0}} $ \ \ \ \ \ \ \ \ \ $ hence $d=\dfrac{4}{7}\sqrt{14} $ $\endgroup$ – Widawensen Jan 15 '18 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.