ideasman42 / isect_segments-bentley_ottmann

BentleyOttmann sweep-line implementation (for finding all intersections in a set of line segments)
MIT License
91 stars 40 forks source link

Question about overlapping / colinear lines #26

Closed vmario89 closed 3 years ago

vmario89 commented 3 years ago

Hi,

i am using your implementation to write a trim-line tool for Inkscape. Basically this already works really fine except that i am not able to handle colinear line segments (lines with same slope) which are overlapping each other. At the moment there are no intersections returned for such cases like in example:

grafik

Do you have some tip for me where to fork in adjusting the code properly to return intersection points, trimmed segments or merged segments?

https://stackoverflow.com/questions/48348228/overlapping-segments-in-bentley-ottmann-algorithm

best regards, Mario

ideasman42 commented 3 years ago

in principle it should be possible to support this using the sweep-line, as news= segments the sweep encountered can be tested again segments already being tracked.

When adding any new segment to the sweep line each segment would need to be tested, to check if it's a continuation of with any existing segments. In principle these segments could then be either merged, or removed in the case of a complete overlap.


A solution that simpler to try out is to pre-process the line segments.

vmario89 commented 3 years ago

i fixed it by implementing another algorithm, found at https://gist.github.com/sbma44/dc34e5005d9827aa7b1c8c11e68b0c6b