Reputation: 607
What is the most efficient algorithm for generating a set of line segments that represent the minimum of a group of line segments (see image)?
The resulting line segments should have following properties:
Upvotes: 0
Views: 196
Reputation:
Seems like a good candidate for a sweepline algorithm.
Create a list of the segment endpoints and tag them with a begin/end flag as well as a reference to the segment. Sort the list by increasing abscissa.
Now scan the list from left to right, while you maintain an active list of segments. Any "begin" point creates a segment entry in the list, an "end" point discards it. At any time, the active list will contain a subset of the segments that are in overlapping configuration between the previous and current "event" points.
By interpolation, evaluate the ordinates at these endpoints and sort them vertically. This allows you to
Finally, you will have to sort the intersections from left to right and in the end you will have a list of subsegments that do not intersect and which are in a total order vertically.
Upvotes: 1