How to find the shortest path between two points under the restriction? Let two different points $M_1(x_1,y_1,z_1)$, $M_2(x_2,y_2,z_2)$ and two nonintersecting lines $l_1$, $l_2$ be given. How to find the shortest path between $M_1$ and $M_2$ which intersects both $l_1$ and $l_2$? 

There is a shorterst path that touches both lines, but needn't be a shortest path that intersects them. Treat any line that is not between $M_1$ and $M_2$ as a $1D$ mirror and the path as that taken by light with angle of incidence=angle of reflection. 
In the worst (two mirror) case, if $l_i$ has direction vector $v_i$ and the ray from $M_1$ initially has direction vector $u$, then if the ray for example touches $l_1$ first then after reflection the new direction vector will be $u'=u-(2u.v_1)v_1$ and after the second reflection $u''=u'-(2u'.v_2)v_2$. From then on the algebra gets tedious. 
