Pasan Sumanaratne
Pasan Sumanaratne

Reputation: 905

Grouping lines considering intersections of each line using python

There are 5 lines. I want to group them considering whether they intersect or not by limiting to the two end points of each line.

I want to get the logic for any of the lines, not being limited to the given scenario. Array of 5 lines (coordinates of end points).

lines_all = [[(1, 10), (5, 10)],[(3, 5), (5, 5)],[(3, 10), (3, 13)],[(5,10),(5,13)],[(3,13),(4,13)]]

5 lines Then finally I want to get the following array list.

result = [[[(1, 10), (5, 10)], [(3, 10), (3, 13)],[(3, 13), (4, 13)]], [[(1, 10), (5, 10)], [(5, 10), (5, 13)]],[(3, 5), (5, 5)]]

final lines

Upvotes: 0

Views: 734

Answers (1)

MBo
MBo

Reputation: 80232

To find all line segment intersections, you can use Bentley-Ottmann algorithm.

Arbitrary found Python implementation

Upvotes: 1

Related Questions