Beruflich Dokumente
Kultur Dokumente
Lecture 3
Line Segment Intersection
Antoine Vigneron
September 9, 2012
2 Preliminary
3 Intersection Detection
4 Intersection reporting
s4 s1 s5
s3
s2
s6
ROAD MAP
Q
P P \Q
Sweep line
The sweep line moves from left to right and stops at event points.
I Convex hull: The event points are just the input points.
I Sometimes they are not known from the start (see intersection
reporting).
We maintain invariants.
I Convex hull: I know the upper hull of the points to the left of the
sweep line.
At each event, restore the invariants.
Degenerate Cases
s0
s
St = (s4 , s5 , s3 )
s3
s1 s7
s6
s5
s2
s4
`t
No intersection Leftmost
intersection
`tf = `t7 `tf +1
Knowing Sti for some i < f , we can easily find Sti+1 . (See next two
slides.)
s4
s1 St3 = (s2 , s3 , s1 )
St4 = (s2 , s3 , s4 , s1 )
s2
s3
s5
`t3 `t4
s4
s1 St4 = (s2 , s3 , s4 , s1 )
St5 = (s2 , s3 , s4 )
s2
s3
s5
`t4 `t5
s0 q
Brute force: Θ(n2 ) time, which is optimal in the worst case, when
there are k = Ω(n2 ) intersections.
If there is 6 1 intersection, the detection algorithm does it in
O(n log n) time which is better.
We will be able to interpolate between these two algorithms, and find
an output-sensitive algorithm.
s4
s1 St = (s5 , s2 , s3 , s4 )
s3
s5 St 0 = (s5 , s3 , s2 , s4 )
s2
Check s4 ∩ s2
`t `t 0 and s3 ∩ s5
At time t, the event queue Q contains all the endpoints with abscissa
larger than t and the intersection point s2 ∩ s3 . At time t 0 , we insert
s3 ∩ s5 into Q.
s1
Some intersection points are inserted several times into Q. How many
times does it happen?
At most twice at each endpoint or intersection point.
I At most 4n + 2k times in total.
It follows that we insert O(n + k) events into Q.
So the algorithm runs in O((n + k) log(n + k)) time.
log(n + k) < log(n + n2 ) = O(log n)
The running time is O((n + k) log n).