Finding Points to Minimize Distance Between Lines (Distance between lines) The points $P = (x,x,x)$ and $Q = (y,3y,-1)$ are on two lines in space that don't meet. Choose x and y to minimize the squared distance $||P - Q||^2$. 
What confuses me here is that I have to find closest points from two lines, rather than finding the best fit line. As far as I know, the projection vector p is the nearest point. Are there any hints that could help me solve this?
Thanks!
 A: What you could do is make an expression for the squared distance ||P-Q||^2. This will be a function of x and y. Now find partial derivatives of this function in both x and y and set equal to zero. Given that it is a quadratic function this should be reasonably straightforward from there. The solutions of the partial derivatives will be the minimum such x,y.
A: Another thing you can do is using vectors and 3d geometry. Treat the points as two lines and you have to find shortest distance between the two. You have lines:
$\vec l= \vec a+ t\vec e$ and
$\vec m=\vec b+ t\vec f$
So here $\vec a$ and $\vec b$ are points on either lines,say a=(0,0,0) and b=(0,0,-1). e and f are vectors along lines. e=(1,1,1) and b=(1,3,-1). So the shortest distance is $\frac {(\vec a-\vec b).(\vec e × \vec f)}{|(\vec e × \vec f)|}$
For proof you can see this:
Find shortest distance between lines in 3D
A: Since you know how to find the nearest point on a line to a fixed point via projection, do that for an arbitrary point on one of the lines, then project back to the original line. The starting and ending points of this double projection are the same iff you started from the nearest point on the first line to the second. This should give you a simple linear equation in $x$ or $y$, depending on which line you started from.
