This preview shows page 1. Sign up to view the full content.
Unformatted text preview: y pair intersect?
d e a
b f Line-segment intersection
Given n line segments, does any pair intersect?
Obvious algorithm: O(n2).
b f Sweep-line algorithm
• Sweep a vertical line from left to right
(conceptually replacing x-coordinate with time).
• Maintain dynamic set S of segments
that intersect the sweep line, ordered
(tentatively) by y-coordinate of intersection.
• Order changes when
• new segment is encountered,
• existing segment finishes, or
• two segments cross
• Key event points are therefore segment endpoints. d
b f e
ff Sweep-line algorithm
Process event points in order by sorting segment
endpoints by x-coordinate and looping through:
• For a left endpoint of segment s:
• Add segment s to dynamic set S.
• Check for intersection between s
and its neighbors in S.
• For a right endpoint of segment s:
• Remove segment s from dynamic set S.
• Check for intersection between
the neighbors of s in S. Analysis
Use red-black tree...
View Full Document