1 / 9

Algorithm FINDINTERSECTIONS( S ) Input: A set S of n line segments

Algorithm FINDINTERSECTIONS( S ) Input: A set S of n line segments Output: The set of intersection points (so that for each intersection point we also return the segments that contain it) Initialize an empty event queue Q

Download Presentation

Algorithm FINDINTERSECTIONS( S ) Input: A set S of n line segments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithm FINDINTERSECTIONS(S) • Input:A set S of n line segments • Output:The set of intersection points (so that for each • intersection point we also return the segments that contain it) • Initialize an empty event queue Q • Insert the segment endpoints into Q (when an upper endpoint is inserted, the corresponding segment should be stored with it) • Initialize an empty status structure T • WhileQ is not emptyDo • Determine the next event point p in Q and delete it. • HANDLEEVENTPOINT(p) • End While

  2. HANDLEEVENTPOINT(p) • U(p)= the set of segments whose upper endpoint is p • (note: segments from U(p) are not in T) • Find all segments stored in T that contain p; they are adjacent in T • L(p) = the subset of segments found whose lower endpoint is p • C(p) = the subset of segments found that contain p in their interior • If L(p)∪U(p)∪C(p) ∪contains more than one segment then • Report p as an intersection, together with L(p), U(p), and C(p) • End If • Delete the segments in L(p) ∪ C(p) from T • Insert the segments in U(p) ∪ C(p) into T The order of the segments in T should correspond to the order in which they are intersected by a sweep line just below (deleting and re-inserting the segments of C(p) reverses their order)

  3. If U(p) ∪C(p) is emptythen • Let SLand SRbe the left and right neighbors of p in T • FINDNEWEVENT( SL , SR , p ) • Else • Let S’ be the leftmost segment of U(p)∪C(p) in T • Let SL be the left neighbor of s in T • FINDNEWEVENT(SL, S’, p) • Let S’’ ‘be the rightmost segment of U(p)∪C(p) in T • Let SR be the right neighbor of S’’ in T • FINDNEWEVENT(S’’ , SR , p)

  4. FINDNEWEVENT(SL , SR, p) • If • SLand SRintersect below the sweep line, or on it and to the right of the current event point p, and the intersection is not yet present as an event in Q • Then • Insert the intersection point as an event into Q

  5. Let q be the maximal number of event points in Q • Let I be the number of intersection points • Note that q ≤ number of intersection points + number of endpoints ≤ n2 (if n > 1)

  6. Algorithm FINDINTERSECTIONS(S) • Input:A set S of line segments • Output:The set of intersection points (so that for each • intersection point we also return the segments that contain it) • Initialize an empty event queue Q • Insert the segment endpoints into Q (when an upper endpoint is inserted, the corresponding segment should be stored with it) • Initialize an empty status structure T • WhileQ is not emptyDo • Determine the next event point p in Q and delete it. • HANDLEEVENTPOINT(p) • End While O(n log n) m(p) O( log n)

  7. HANDLEEVENTPOINT(p) • U(p)= the set of segments whose upper endpoint is p • Find all segments stored in T that contain p; they are adjacent in T • L(p) = the subset of segments found whose lower endpoint is p • C(p) = the subset of segments found that contain p in their interior • IfL(p)∪U(p) ∪ C(p) ∪contains more than one segmentthen • Report p as an intersection, together with L(p), U(p), and C(p) • End If • Delete the segments in L(p) ∪ C(p) from T • Insert the segments in U(p) ∪ C(p) into T The order of the segments in T should correspond to the order in which they are intersected by a sweep line just below (deleting and re-inserting the segments of C(p) reverses their order) (|L(p)|+|U(p)|+|C(p)|)O( log n) = m(p) O( log n) (|L(p)|+|U(p)|+|C(p)|)O( log n) = m(p) O( log n) (|L(p)|+|C(p)|)O( log n) (|U(p)|+|C(p)|)O( log n)

  8. IfU(p) ∪C(p) is emptythen • Let SLand SRbe the left and right neighbors of p in T • FINDNEWEVENT( SL , SR , p ) • Else • Let S’ be the leftmost segment of U(p)∪C(p) in T • Let SL be the left neighbor of s in T • FINDNEWEVENT(SL, S’, p) • Let S’ be the rightmost segment of U(p)∪C(p) in T • Let SR be the right neighbor of S’ in T • FINDNEWEVENT(s, sr, p) O(log n) O(log n) O(log n)

  9. FINDNEWEVENT(SL , SR, p) • If • SLand SRintersect below the sweep line, or on it and to the right of the current event point p, and the intersection is not yet present as an event in Q • Then • Insert the intersection point as an event into Q O(log q) ≤ O(log n2) ≤ O(2 log n) = O(log n)

More Related