Unformatted text preview: y pair intersect?
d e a
c
b f Linesegment intersection
Given n line segments, does any pair intersect?
Obvious algorithm: O(n2).
e
d
a
c
b f Sweepline algorithm
• Sweep a vertical line from left to right
(conceptually replacing xcoordinate with time).
• Maintain dynamic set S of segments
that intersect the sweep line, ordered
(tentatively) by ycoordinate of intersection.
• Order changes when
• new segment is encountered,
segment
• existing segment finishes, or
endpoints
• two segments cross
• Key event points are therefore segment endpoints. d
aa
acc
abbb e
d
c
b d
c
b e
ed
db
bf e
d
a
c
b f e
b
d
f b
ee
dd
ff Sweepline algorithm
Process event points in order by sorting segment
endpoints by xcoordinate 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 redblack tree...
View
Full Document
 Fall '08
 UNGOR
 Algorithms, Data Mining, Databases

Click to edit the document details