I'm working on a task (with python3) which needs to check if 2 line segments are overlap and can return the 2 end points. The line segment has coordinates in (x1, y1, x2, y2) form, which (x1,y1) and (x2,y2) is the coordinates of its end points. The 2 lines are pretty close to each other, but might not be parallel. You can see the picture to understand which case is called overlap. I think the overlap definition can be said "if the projection of one point lies between 2 endpoints of the other line" Example:
overlap1 = numpy.array([[1,4,5,5], [7,7,3,5]])
overlap2 = numpy.array([[8,1,12,2], [9,2,11,3]])
non_overlap = numpy.array([[1,2,5,3], [6,3,9,4]])
My goal is to find the 2 furthest points of 4 points if they are overlap, as the red circle shows in the image. Currently my idea is:
- calculate distance from all points (AB, AC, AD, BC, BD, CD) and check to find the max distance, called max_len
- Calculate: test = len_AB + len_CD - max_len
- If test > 0, they are overlap, otherwise they aren't
This alg works pretty good to check the overlap condition but difficult to return the 2 most end points.
What do you think about this problem? Thank you.