# Computing the minimum distance between two hollow tubes provided a method for computing the minimum distance between finite line segments

Say I have a method of calculating the minimum distance between two finite line segments in three-dimensional space. How might I adapt this method to provide the minimum distance between the surfaces of two hollow tubes of radii $R_1$ & $R_2$ and respective lengths $L_1$ & $L_2$?

At the limit of having long hollow tubes, where the point of closest approach is near their respective mid-points, the simpler line segment to line segment distance suffices. However, how does one handle the case where the tubes fail to have the same slope and the point of closest approach is near one or the other tube's end?

Note - There are no circular 'end-caps' on the tubes referenced in this problem.

-
"The line segment to line segment distance also is also equivalent to the tube-to-tube distance (subtracting R1 and R2) if the two tubes are parallel." This is twice wrong: firstly, the tubes don't have to be parallel for this to be true, if they are long enough; secondly, your statement is wrong -- even if the tubes are parallel -- if the tubes are staggered (i.e. the points of closest approach are on the rims). –  TonyK Jan 18 '12 at 8:55
@TonyK My intention was to cover the case of long cylinders with the statement: "At the limit of having long hollow tubes, where the point of closest approach is near their respective mid-points...". Good point about the staggered tubes. –  Steve Jan 18 '12 at 9:21

For each tube, its point of closest approach can be on its curved surface, or on one of its two rims -- three possibilities. So there are nine possibilities for the two tubes combined. I think the simplest solution is to try all nine (rejecting curved-surface solutions that are off the end of the tube) and pick the smallest. For this you need three different algorithms:

1. Closest approach of two infinite cylinders;
2. Closest approach of two circles in $\mathbb R^3$;
3. Closest approach of a circle and an infinite cylinder.

As far as I can see, none of these is made easier by knowing the distance between two finite line segments.

Edited to add: I just realised that Algorithm 3 must return all local minima (there may be two of them), in case the global minimum is off the end of the tube.

-

My intuition says to start by evaluating the case where both cylinders have radius 0. This would give you a jumping off point. After that, you'd be able to narrow down some decent neighborhoods by sheer reason. Then, I'd parametrize the surfaces of the cylinders as vector functions in x, y and z. I think -- and this is just intuition here -- that and answer should pop out, if not by logic as I said before, then by using Lagrange multipliers constrained to the neighborhoods you found with 2 vector functions in x, y and z. Just a thought.

-
The minimum line segment to line segment distance should be equivalent to the minimum distance between two cylinders of radius zero. –  Steve Jan 18 '12 at 7:39
I'm saying that if the answer isn't obvious, as it would be in the zero radius case, try writing the cylinders as parametric surfaces. Then write a function describing the distance between those two surfaces. Use you're favorite optimization method to find a min and you're golden. –  N.G. Jan 18 '12 at 7:42