Finding a connecting line between two lines in 3D space, with specific requirements for its length. Given, in 3D space: a point $P$ and a direction $v$, a point $Q$ and a direction $w$. So, two lines, $L_1 = P + tv$, $L_2 = Q + tw$.
I am looking for two points, one on each line, say P' and Q'. My requirement is that the distance from $P$ to $P'$ plus $Q$ to $Q'$ equals the distance from $P'$ to $Q'$:
$$||P-P'|| + ||Q-Q'|| = ||P'-Q'||$$
Any suggestions on how to solve this? I have some experience with linear algebra, but it is rusty. My end goal is a function into which I can feed the coordinates of the two points and the two direction vectors and have it return the solution(s) t.
UPDATE: I have changed the parameter for the line equations, they now both use the same parameter instead of separate ones. I hope this will make it solvable...
 A: PART 1
You probably want an algorithm to find the answer. I am ignoring the trivial case of parallel lines. 
Consider the points $P'$ and $Q'$ as moving points along their respective lines. Now consider the four possible cases -


*

*$P'$ moves in $+v$ direction, $Q'$ moves in $+w$ direction.

*$P'$ moves in $+v$ direction, $Q'$ moves in $-w$ direction.

*$P'$ moves in $-v$ direction, $Q'$ moves in $+w$ direction.

*$P'$ moves in $-v$ direction, $Q'$ moves in $-w$ direction.


In all the cases if you move very far, the distance between $P'$ and $Q'$ will ultimately start increasing. Remember the lines are not parallel. But in some of the cases the distance may first decrease and then increase. Choose the case of decreasing distance.
Now find out the minimum distance between these two lines. Say this minimum is attained at $P_0$ and $Q_0$. Clearly among the four cases outlined above whichever case moves $P'$ closer to $P_0$ and $Q'$ closer to $Q_0$ is the case we have chosen.
Suppose $\|P-P_0\| + \|Q-Q_0\|\leq\|P_0-Q_0\|$, then there must exist a solution because the sum $\|P-P'\| + \|Q-Q'\|$ start with $0$ and increases whereas $\|P'-Q'\|$ starts with $\|P-Q\|$ and decreases to $\|P_0-Q_0\|$ as you start moving the points. [Note that initially $P'=P$ and $Q'=Q$].
To find this solution you just have to move $P'$ from $P$ to $P_0$ and $Q'$ from $Q$ to $Q_0$. Somewhere you will find it.
However if $\|P-P_0\| + \|Q-Q_0\|\leq\|P_0-Q_0\|$ does not hold, then this algorithm will not work. I will try those cases presently and get back.
A: PART - 2
I keep the notation as above. To wit, $P,Q$ are the fixed points on $L_1,L_2$. The vectors $v,w$ are the direction vector along $L_1,L_2$ and $P',Q'$ are the points to be found. Define two function $f,g:L_1\times L_2\rightarrow\mathbb{R}_{\geq0}$ as follows :


*

*$f(P',Q')= \|P'-Q'\|$

*$g(P',Q')=\|P-P'\| + \|Q-Q'\|$


Note that $f$ has a minimum and is attained at $P_0$ and $Q_0$ as our earlier notation says. The function $g$ has minimum $0$.
We estimate these two functions for their growth characteristics. Also remember the four cases outlined in part 1. I define the condition $\|P-P_0\| + \|Q-Q_0\|\leq\|P_0-Q_0\|$ as $K$. 
From part 1 it follows that if $K$ is true then there is a solution. And it involves choosing that case which moves $P',Q'$ closer to $P_0,Q_0$. Now I will describe the solution if $K$ does not hold.
Define the function $d_1,d_2:\mathbb{R}_{\geq0}\rightarrow\mathbb{R}_{\geq0}$ as $d_1(t)=f(P+tv,Q+tw)$ and $d_2(t)=g(P+tv,Q+tw)$. Notice that of the four cases outlined above we can study all of them by just redefining $v$ & $w$ as either positive or negative of it. So without defining too many things we can consider all the cases with the same $d_1$ & $d_2$ one by one.


*

*$d_2(t)=t\|v\|+\|w\|$. this is a linear function which starts from $0$ and increases without bound with a slope of $\|v\|+\|w\|$.

*$d_1(t)=\|P-Q + t(v-w)\| \leq \|P-Q\| + t\|v-w\|$. The growth of $d_2$ starts with a positive number, is ultimately a linear growth with a slope less than $\|v-w\|$.


Now the four cases come into play. Choosing any case is equivalent to redefining $v,w$ as either positive or negative of it. So choose that case which makes $\|v-w\|$ strictly smaller than $\|v\|+\|w\|$. Now observe the behavior of the graph of $d_1$ & $d_2$. Both of them are straight lines with different slopes and start with different values at $t=0$. So they must intersect. And that gives the solution.
Note :


*

*Actually $d_2$ may not be a straight line initially but for large values of $t$, it is ultimately a straight line and hence the conclusions remain unchanged.

*There may be more solutions which are not described by this method. One of the reasons is that we have chosen to move $P'$ and $Q'$ in tandem. If we move them independently by accepting two parameters $t$ and $s$, we may find other solutions too. But still there cud be more solutions.

