Hey mate,

Whilst I'm sure there is a more efficient way of solving this, the following thought came to mind,

Any point P can be expressed as P(t) = ( x1(t) , y1(t) , z1(t) )

Similarly, Q = Q(t) =( x2(t) , y2(t) , z2(t) )

**I will impose that the two lines do not intersect, (which can easily be shown as the evaluation of P(t) = Q(t) - however I imagine no solution for t exists).

Then for any value of t the Distance between the points P(t), Q(t) is solved simply using,

Dist(t) = sqrt( ( x2(t) - x1(t) )^2 + ( y2(t) - y1(t) )^2 + ( z2(t) - z1(t) )^2 )

We observe that our original problem now involves a simply 1D minimisation problem,

To be honest I don't have to strength to plug through the algebra, so I will attempt this in a general sense.

Following high school mathematics, to identify any relative extrema solve,

d/dt ( Dist(t) ) = 0

d/dt ( Dist(t) ) = L(t)/(2*Dist(t)) = 0

Where L(t) = 2 ( x2(t) - x1(t) ) ( d/dt (x2(t) - x1(t) ) + ....

as x1(t) , x2(t) , ... , z2(t) are linear, thus there derivatives are merely constant values, Hence L(t) is a linear polynomial.

Returning to our original problem,

d/dt ( Dist(t) ) = L(t)/(2*Dist(t)) = 0

Given our assumption that Dist(t) ~= 0 for all t, then we arrive at the simplified equation,

d/dt ( Dist(t) ) = L(t)/(2*Dist(t)) = L(t) = 0

Which given the nature of L(t) has a definate simple solution say t* and thus form the single point of relative extrema has been found, whilst one may state due to the nature of P(t), Q(t) that this point must reflect a relative minima we will persue onward and enforce this using the double derivative test,

thus,

d^2/dt^2 ( Dist(t) ) = (1/2)*( Dist(t) (d/dt ( L(t) ) - L(t) (d/dt ( Dist(t) ) ) / (Dist(t)^2)

At t = t* L(t) = 0,

thus,

d^2/dt^2 ( Dist(t) ) = (1/2)*( Dist(t) (d/dt ( L(t) ) / ( Dist(t)^2 )

= (1/2)*( d/dt( L(t) )/ Dist(t) )

Given the nature of Dist(t) we observe Dist(t) > 0 and thus for t = t* to be a relative minimina d/dt( L(t) ) at t = t* must be positive - which Im sure it will be.

Once this has been achieved simply sub in the value t = t* into P(t), Q(t) and Dist(t) and you will have identified the points P, Q and the length PQ

Hope this helps,

David