# Finding points on two linear lines which are a particular distance apart

I have two linear, skew, 3D lines, and I was wondering how I could find a points on each of the lines whereby the distance between the two points are a particular distance apart?

I'm not after the points where the lines are the closest distance apart, nor the furthest distance apart, nor the point at which the lines cross! I'm after the points on the lines where the two lines are a particular distance apart. I'd like to also be able to change this distance and find the new points.

Thanks very much in advance! :)

-
As Elvind says, there is a minimum below which there is no solution. An approach to finding that minimum in one particular case is shown at math.stackexchange.com/questions/19797/…. Above that distance, there will be a range of points on each line, not a unique solution. –  Ross Millikan Mar 17 '11 at 13:45

Here is one way to do it. Assuming you have (or are able to find) a parametric equation for the lines on the form \begin{align} l: \begin{cases} x=x_{l0}+at \\ y=y_{l0}+bt \\ z=z_{l0}+ct \end{cases}, \qquad m: \begin{cases} x=x_{m0}+ds \\ y=y_{m0}+es \\ z=z_{m0}+fs \end{cases}. \end{align}

Then, $P_0=(x_{l0}+at,y_{l0}+bt,z_{l0}+ct)$ is a general point on the line $l$ and $Q_0=(x_{m0}+ds,y_{m0}+es,z_{m0}+fs)$ a point on $m$.

We can find a vector $\overrightarrow{P_0Q_0}$ from a point on $l$ to a point on $m$: $$\overrightarrow{P_0Q_0} = (x_{m0}+ds-x_{l0}-at,y_{m0}+es-y_{l0}-bt,z_{m0}+fs - z_{l0}-at)$$ The distance of the vector is given by $$||\overrightarrow{P_0Q_0}|| = \sqrt{(x_{m0}+ds-x_{l0}-at)^2 +(y_{m0}+es-y_{l0}-bt)^2 + (z_{m0}+fs - z_{l0}-at)^2}.$$ In other words, if we let $D$ denote your distance, then $$D^2=(x_{m0}+ds-x_{l0}-at)^2 +(y_{m0}+es-y_{l0}-bt)^2 + (z_{m0}+fs - z_{l0}-at)^2 .$$ This may not be the best way to do it. It could be difficult to find a $t$ and an $s$ that fits, and there will probably be several. If you are able to first choose a point on one line, and then find a point on the other line with desired distance, it will be easier and you will only get two solutions (at most).

-
Thanks for the help - this makes a lot of sense to me but I'm still trying to figure out how to calculate the values of s and t. I've put some values into this equation and I'm left with a linear equation of d = xs + yt. I've tried multiplying the equation by two and then using Cramner's rule to find the values of s and t but I didn't get valid values. Should this method work? Thanks very much again. –  James Bedford Mar 17 '11 at 21:06
If you're left with the equation $d=xs+yt$, this method worked better than I feared. Now you can, for instance, express $s$ as a function of $t$: $s=\frac{d-yt}{x}$. Put in values for $t$ and get corresponding values for $s$. When you put each of these values into the expressions for $P_0$ and $Q_0$, you will get different points with desired distance between them. As mentioned earlier, there is usually not just one solution. –  please delete me Mar 17 '11 at 21:48
Yea, the problem is that both s and t are unknowns which I need to find? –  James Bedford Mar 17 '11 at 21:59
The equation $d=xs+yt$ has infinitely many solutions, because no matter what $s$ is, there is a $t$ that fits into the equation along with it. If we call this combination of $s$ and $t$ a pair, then each pair will make different pairs of points, and all of these pairs of points will have a distance of $d$ between them. Roughly, this means that you can choose an arbitrary point on the line $l$, find its $t$, plug the $t$ into the equation and get an $s$. This $s$ will determine a point on $m$ with the disance $d$ to the point on $l$. Hope this makes it clearer. –  please delete me Mar 17 '11 at 22:27
Ahh yes I see the problem now! I was having trouble visualizing it. I think this sort of problem isn't the correct one I need to be solving for my situation, but at least I understand it now! Thanks very much for your help! –  James Bedford Mar 18 '11 at 8:33

In general, this is not possible for all distances. If the lines do not cross, there willl be a minimum distance between the lines which you can never reach below, but you should be able to solve it for all distances equal to or larger than this minimum distance.

Since the general case has been shown by Eivind, I will take the special case where the lines do cross, so a solution is guaranteed.

If the lines, say $l$ and $m$, do cross, you can write them as:

\begin{align} l(t)&= \mathbf a + t \mathbf b \\ m(s)&= \mathbf a + s \mathbf c \end{align}

The distance between two lines will be $\|l(t) - m(s)\| = \| t \mathbf b - s \mathbf c\|$. Say you want this to be equal to $d$, then you can solve for $d^2$ (I am here assuming that you are working in $\mathbb R^3$):

\begin{align} d^2 &= \langle \mathbf b t - \mathbf c s, \mathbf b t - \mathbf c s \rangle = \langle \mathbf b t, \mathbf b t - \mathbf c s \rangle - \langle \mathbf c s, \mathbf b t - \mathbf c s \rangle \\ &= \langle \mathbf b t, \mathbf b t \rangle - 2 \langle \mathbf b t, \mathbf c s \rangle + \langle \mathbf c s, \mathbf c s \rangle = \\ &= t^2\|b\|^2 + s^2 \|c\|^2 - 2 \langle \mathbf b t, \mathbf c s \rangle \end{align}

If you have normalized $\mathbf b$ and $\mathbf c$, this will reduce to:

$$d^2 = t^2 + s^2 - 2 (b_1c_1 + b_2c_2 + b_3c_3) ts$$

Which you can solve. You can here choose a value for $t$ (which will tell you how far the crossing point the point on line $l$ is) and then solve for $s$. If you want the points to be on equal distance from the crossing point, take $t = s$.

-