1
votes

Different articles have discussed about the intersection of two line segments in Python such as

How do I compute the intersection point of two lines?,

Numpy and line intersections,

How can I check if two segments intersect?

But, no one made it perfect since, they did not cover an especial case. Given the following two line segments:

a = [(0, 2), (2, 4)]
b = [(-2, 0), (0, 2)]

These two segment lines have the same slope. In fact, they intersect at (0, 2). How can we obtain such the intersection point?

The second part of my question, what if two line segments overlap (partially/totally)? That is,

a = [(0, 2), (2, 4)]
b = [(-2, 0), (1, 3)]
1
"These two segment lines have the same slope but, not parallel" doesn't really make sense since "parallel" means "same slope".John Coleman
@Woodford Clearly, they are common at (0, 2).Javad.Rad
There are infinitely many points of "intersection" (overlap) between (0, 2) and (1, 3). Which one(s) do you want?Woodford
Does this answer your question? How can I check if two segments intersect?balmy
@balmy I didn't see so. Where do you mean exactly?Javad.Rad

1 Answers

1
votes

In your last reference, the first answer returns False if A1 == A2 due to the fact the lines are parallel. You present a legitimate edge case, so all you need to do in case the lines are parallel is to also check if they both lie on the same line. This is by checking if b1 == b2. Only if this condition is False, return False as the segments are parallel but do not lie on the same hyperplane. Otherwise, continue as the answer specifies, this is by checking if both segments has a common point.