How do I place two points on two axis-aligned line segments such that they have given Euclidean distance l? This is my problem:
I am given two axis aligned line segments $l_1$ and $l_2$ of finite length and a distance $l$.
How do I find points $p_1 \in l_1$ and $p_2 \in l_2$, such that  $||p_1-p_2||_2 = l$?
Thanks in advance for any help! :)
 A: I don't think there is a simple way because there are several cases.  If the segments are parallel, you can compute the distance $d$ between the lines they are part of.  For example, if they are $x$ aligned you just take the difference in the $y$ coordinates.  Then you are looking for points on them that are $\sqrt {l^2-d^2}$ apart in $x$  Start with the two ends of the short one and see if one of the two choices is on the other.  
If they are aligned to different axes, the shortest distance between them may be from an endpoint of one to a middle point of the other.  For example, you might have $(-1,0)$ to $(1,0)$ and $(0,1)$ to $(0,5)$.  The longest distance is between two of the endpoints.  If you find the shortest and longest, you will know whether there is a solution by whether $l$ is between them.  Finding the distance from a point to a line segment is discussed here and here  My example above shows why it is hard to define an algorithm.  If you have $l=3$ you need to use a middle point of the vertical segment.
