Introduction and Line Segment Intersection
Introduction and Line Segment Intersection
Introduction
Plane (two-dimensional), R2
Space (three-dimensional), R3
Space (higher-dimensional), Rd
Convexity
Description size
Description size
Computation time
any intersection?
find all intersections
Geometric Algorithms Lecture 1: Introduction and line segment intersection
Course Organization Geometric objects
Introduction Geometric relations
Line segment intersection Combinatorial complexity
Plane sweep Computational geometry
Map layers
Map overlay
Map overlay
Algorithm FindIntersections(S)
Input. A set S of line segments in the plane.
Output. The set of intersection points among the segments in S.
1. for each pair of line segments ei , ej ∈ S
2. do if ei and ej intersect
3. then report their intersection point
Output-sensitive algorithm
First attempt
Second attempt
Plane sweep
Sweep
computed
unexplored
Geometric Algorithms Lecture 1: Introduction and line segment intersection
Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency
computed
status
unexplored
Geometric Algorithms Lecture 1: Introduction and line segment intersection
Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency
The events occur when the status changes, and when output
is generated
s1
s3 s2
s4
s5 add s1
s6
s7
s8
s1
s3 s2
s4
s5 add s2 after s1
s6
s7
s8
s1
s3 s2
s4
add s3 between s1
s5 and s2
s6
s7
s8
s1
s3 s2
s4
s5 add s4 before s1
s6
s7
s8
s1
s3 s2
s4
report intersection
s5 (s1 , s2 ); swap s1
and s3
s6
s7
s8
s1
s3 s2
s4
remove s2
s5
s6
s7
s8
s1
s3 s2
s4
remove s1
s5
s6
s7
s8
s1
s3 s2
s4
s5 add s5
s6
s7
s8
s1
s3 s2
s4
report intersection
s5 (s3 , s4 ); swap s3
and s4
s6
s7
s8
. . . and so on . . .
The events
Status structure
We use a balanced binary search tree with the line segments
in the leaves as the status structure
s4
s2 s6
s1 s3 s5 s7
s1 s2 s3 s4 s5 s6 s7 s8
s1 s2 s5 s6 s8
s3 s4
s7
Geometric Algorithms Lecture 1: Introduction and line segment intersection
Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency
Status structure
s4
s2 s6
s1 s3 s5 s7
s1 s2 s3 s4 s5 s6 s7 s8
s1 s2 s5 s6 s8
s3 s4
s9 s7
Status structure
s4
s2 s6
s1 s3 s5 s7
s1 s2 s3 s4 s5 s6 s7 s8
s1 s2 s5 s6 s8
s3 s4
s9 s7
Status structure
s4
s2 s6
s1 s3 s5 s7
s1 s2 s9 s4 s5 s6 s7 s8
s9 s3
s1 s2 s5 s6 s8
s3 s4
s9 s7
Status structure
Finding events
Finding events
si
sj
Lemma: Two line segments si and sj can
only intersect after (= below) they have
become horizontal neighbors
Proof: Just imagine that the sweep line is
ever so slightly above the intersection point
of si and sj , but below any other event si
sj
Also: some earlier (= higher) event made
si and sj horizontally adjacent!!!
Event list
Algorithm FindIntersections(S)
Input. A set S of line segments in the plane.
Output. The intersection points of the segments in S, with for
each intersection point the segments that contain it.
1. Initialize an empty event queue Q. Next, insert the
segment endpoints into Q; when an upper endpoint is
inserted, the corresponding segment should be stored
with it
2. Initialize an empty status structure T
3. while Q is not empty
4. do Determine next event point p in Q and delete it
5. HandleEventPoint(p)
Event handling
Event handling
Event handling
Event handling
Event handling
1 Exchange s and s0 in T s s0
2 If s0 and its new left neighbor in p
T intersect below the sweep
line, then insert this intersection
point in Q
3 ...
4 ...
Event handling
If the event is an intersection point
event where s and s0 intersect at p:
1 Exchange s and s0 in T
2 If s0 and its new left neighbor in s s0
T intersect below the sweep
p
line, then insert this intersection
point in Q
3 If s and its new right neighbor
in T intersect below the sweep
line, then insert this intersection
point in Q
4 ...
Event handling
If the event is an intersection point
event where s and s0 intersect at p:
1 Exchange s and s0 in T
2 If s0 and its new left neighbor in s s0
T intersect below the sweep
p
line, then insert this intersection
point in Q
3 If s and its new right neighbor
in T intersect below the sweep
line, then insert this intersection
point in Q
4 Report the intersection point
Event handling
Efficiency
Efficiency
Efficiency
Initialization takes O(n log n) time (to put all upper and lower
endpoint events in Q)
Efficiency
Efficiency
Question: Given that the event list is a binary tree that may
store O(k) = O(n2 ) events, is the efficiency in jeopardy?
Degenerate cases
Degenerate cases
How about multiply coinciding event points?
Let U(p) and L(p) be the line segments that have p as upper
and lower endpoint, and C(p) the ones that contain p
Conclusion