0

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:

  1. Do not overlap
  2. Each segment must fall within one segment of the original set
  3. No point on any segment of the original set can fall beneath it

enter image description here

Darko
  • 589
  • 1
  • 7
  • 18
  • Looks like you're looking for the bottom half of a convex hull? Try sorting your points based on their angle off the horizontal and connecting lines like that? If that's not it, try being more clear in your description. – Jacob Steinebronn Aug 14 '20 at 19:24
  • @JacobSteinebronn this is not a convex hull (but a convex hull will work for the requirement) – Alberto Sinigaglia Aug 14 '20 at 19:24
  • The provided result isn't one, but by all restrictions it looks like a convex hull is correct. – Jacob Steinebronn Aug 14 '20 at 19:25
  • @Jacob: OP's example image is clearly nonconvex. – Richard Aug 14 '20 at 19:26
  • @Richard see my above comment lol – Jacob Steinebronn Aug 14 '20 at 19:27
  • You'll likely need to modify a [sweep line algorithm](https://en.wikipedia.org/wiki/Sweep_line_algorithm). – Richard Aug 14 '20 at 19:29
  • @Richard, yes that is the general algorithmic space I have been searching and I actually am making good progress on a sweep-line approach. It seemed like the type of problem that may have already been solved though so I wanted to see if the community had a more specific recommendation. – Darko Aug 14 '20 at 19:32
  • 1
    Why does the resulting line not move upwards between X=250 and 300, to follow the segment that is up there? – trincot Aug 14 '20 at 20:39
  • 1
    @trincot. That was a drawing error on my part. I will fix it. – Darko Aug 14 '20 at 21:12

1 Answers1

1

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

  • detect the intersections (which correspond to re-orderings in the vertical list),
  • find the lowest ordinates.

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.

  • Sorry that I can't make a more detailed description. I can't do better without a complete implementation. I hope this will be helpful anyway. –  Aug 15 '20 at 08:08