The Generalization of Bentley-Ottmann Algorithm

前端 未结 2 756
悲&欢浪女
悲&欢浪女 2020-12-16 04:58

Bentley-Ottmann Algorithm is used to determined the intersection point of a list of lines. However as mentioned here in Wiki, there are a few drawbacks:

相关标签:
2条回答
  • 2020-12-16 05:36

    The Wikipedia article you linked to has a section on handling these special positions, which suggests these modifications to the basic algorithm:

    • By convention, a point is to the "left" of a point vertically above it; thus the "left" endpoint of a vertical line is its lower endpoint.
    • Events may consist of the crossings of two or more lines.
    • When an event point is reached, its incident segments must be reversed in the sweep line (not just swapped, as there may be more than two).
    • After a crossing is handled, there may be more than two old event points to be removed or more than two new event points to be inserted.
    0 讨论(0)
  • 2020-12-16 05:53

    These are the modifications to the algorithm proposed by Skanthak here:.

    The algorithm proceeds as follows: It first creates events for all start- and endpoints of input segments. It then handles all events in sorted order.
     For each event, it fetches the associated list L of segments starting at that point and finds and removes all segments in the search tree that intersect the current event point. It reports all those segments as intersections in that point. It then switches the order of the comparison function by changing the flag to be slightly after the current event. It reinserts all previously removed segments that do not have their endpoint at the current event point (because they have to be removed from the structure at this point anyways) and additionally insert the segments from L (that are starting at this point). It checks the top and bottom neighbors above and below the current event point for new intersections and adds them as event points if it finds any.
     This way the algorithm is robust against all kinds of degeneracies, including vertical segments and overlapping segments, as well as segments intersecting on their endpoints.

    for all segments s do
      Create events for the endpoints of s
    end for
    while event queue not empty do
      Remove the smallest event point p from the queue
      Let L be the set of segments that start at p
      I ← all segments in the sweep line structure that contain p
      remove I from sweep line structure
      if |L| + |I| ≥ 2 then
         Report intersections of L ∪ I
      end if
      C ← {s ∈ I | p is not endpoint of s}
      Insert C in sweep line structure in reversed order
      Check for new intersections among segments above and below p
    end while
    
    0 讨论(0)
提交回复
热议问题