I had a question regarding 2 line segments. Say we have 2 line segments whose origin and lengths are given as: (P0, L0) and (P1, L1) respectively. I need to find when can they end at the same point. The line segments lie anywhere in 3D space.

One of the approaches I could think about is: Let's say this common end point is T and the points are A and B. So for the line segments with A and B as origins, A,B and T must form a triangle. Length of vector AT = L0 and length of vector BT = L1. But since the orientation of the line segment is not known, there can be a lot of possibilities. Lets say we choose a particular orientation for line segment AT as (i,j,k) - 1st octant. So now we can move anywhere in space from T but only by a distance L1 to find BT.

If you just want to know whether a solution exists or not, you just have to check the triangle inequalities. Define d = distance(P0, P1). Then there is a solution if and only if d <= L0+L1 and d >= abs(L0-L1).

Thanks for the d >= abs(L0-L1) info.. I had figured out the L0+L1 part. Both of these would give if a solution exists or not. But I also want to know the configuration of the 2 line segments, as in also the point as well. I want my function to return a list of all such points. Because if I think of a brute force way, I can find atleast 3 points by moving by L0 parallel to the 3 axes. The other points can be found by breaking L0 into x,y and z components if I am write. So if i have to iterate through a loop, how can I find the range of the loop it does not exactly go on a particular order when finding the point.