0% found this document useful (0 votes)
7 views14 pages

Sweepline 2

The document discusses plane sweep algorithms for geometric intersections, focusing on line segment intersection in computational geometry. It outlines the importance of this problem in various fields such as robotics and computer graphics, and presents an output-sensitive algorithm with a runtime of O((n+k) log n). The document also details the event handling process and runtime analysis of the sweep line algorithm.

Uploaded by

Anant Nimkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views14 pages

Sweepline 2

The document discusses plane sweep algorithms for geometric intersections, focusing on line segment intersection in computational geometry. It outlines the importance of this problem in various fields such as robotics and computer graphics, and presents an output-sensitive algorithm with a runtime of O((n+k) log n). The document also details the event handling process and runtime analysis of the sweep line algorithm.

Uploaded by

Anant Nimkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

CMPS 3130/6130 Computational Geometry

Spring 2015

Plane Sweep Algorithms II


Carola Wenk

1/22/15 CMPS 3130/6130 Computational Geometry 1


Geometric Intersections

• Important and basic problem in Computational


Geometry
• Solid modeling: Build shapes by applying set
operations (intersection, union).
• Robotics: Collision detection and avoidance
• Geographic information systems: Overlay two
subdivisions (e.g., road network and river
network)
• Computer graphics: Ray shooting to render scenes

1/22/15 CMPS 3130/6130 Computational Geometry 2


Line Segment Intersection
• Input: A set S={s1, …, sn} of (closed) line
segments in R2
• Output: All intersection points between segments
in S

1/22/15 CMPS 3130/6130 Computational Geometry 3


Line Segment Intersection
• n line segments can intersect as few as 0 and as many as
n =O(n2) times
2
• Simple algorithm: Try out all pairs of line segments
→ Takes O(n2) time
→ Is optimal in worst case
• Challenge: Develop an output-sensitive algorithm
– Runtime depends on size k of the output
– Here: 0  k  c n2 , where c is a constant
– Our algorithm will have runtime: O( (n+k) log n)

– Best possible runtime: O(n log n + k)


→ O(n2) in worst case, but better in general

1/22/15 CMPS 3130/6130 Computational Geometry 4


Complexity
• Why is runtime O(n log n + k) optimal?
• The element uniqueness problem requires (n log n)
time in algebraic decision tree model of computation (Ben-Or
’83)
• Element uniqueness: Given n real numbers, are all of
them distinct?
• Solve element uniqueness using line segment
intersection:
– Take n numbers, convert into vertical line segments. There is an
intersection iff there are duplicate numbers.
– If we could solve line segment intersection in o(n log n) time, i.e.,
strictly faster than Θ(n log n), then element uniqueness could be
solved faster. Contradiction.

1/22/15 CMPS 3130/6130 Computational Geometry 5


Plane sweep
algorithm
• Cleanliness property:
– All intersections to the left of sweep line l have been reported
• Sweep line status:
– Store segments that intersect the sweep line l, ordered along
the intersection with l .
• Events:
– Points in time when sweep line status changes combinatorially
(i.e., the order of segments intersecting l changes)
→ Endpoints of segments (insert in beginning)
→ Intersection points (compute on the fly during plane sweep)

1/22/15 CMPS 3130/6130 Computational Geometry 6


General position
Assume that “nasty” special cases don’t happen:
– No line segment is vertical
– Two segments intersect in at most one point
– No three segments intersect in a common point

1/22/15 CMPS 3130/6130 Computational Geometry 7


Event Queue
• Need to keep events sorted:
– Lexicographic order (first by x-coordinate, and if two
events have same x-coordinate then by y-coordinate)
• Need to be able to remove next point, and insert new
points in O(log n) time
• Need to make sure not to process same event twice
 Use a priority queue (heap), and possibly extract
multiples
 Or, use balanced binary search tree

1/22/15 CMPS 3130/6130 Computational Geometry 8


Sweep Line Status
• Store segments that intersect the sweep line l, ordered along the
intersection with l .
• Need to insert, delete, and find adjacent neighbor in O(log n) time
• Use balanced binary search tree, storing the order in which
segments intersect l in leaves
b
c

e d

c
b
e
d
1/22/15 CMPS 3130/6130 Computational Geometry 9
Event Handling
1. Left segment endpoint
– Add new segment to sweep line status
– Test adjacent segments on sweep line l for intersection with new
segment (see Lemma)
– Add new intersection points to event queue

b
c

a e d

cc
bb
de
d
1/22/15 CMPS 3130/6130 Computational Geometry 10
Event Handling
2. Intersection point
– Report new intersection point
– Two segments change order along l
→ Test new adjacent segments for new intersection points (to
insert into event queue)

b
c

a e d

c c Note: “new” intersection


b e might have been already
e b detected earlier.
d d
1/22/15 CMPS 3130/6130 Computational Geometry 11
Event Handling
3. Right segment endpoint
– Delete segment from sweep line status
– Two segments become adjacent. Check for intersection points (to
insert in event queue)

b
c

a e d

ee
cc
bd
d
1/22/15 CMPS 3130/6130 Computational Geometry 12
Intersection Lemma

• Lemma: Let s, s’ be two non-vertical segments whose


interiors intersect in a single point p. Assume there is no
third segment passing through p. Then there is an event
point to the left of p where s and s’ become adjacent (and
hence are tested for intersection).
• Proof: Consider placement of sweep line infinitesimally
left of p. s and s’ are adjacent along sweep line. Hence
there must have been a previous event point where s and
s’ become adjacent.
s’

p
s

1/22/15 CMPS 3130/6130 Computational Geometry 13


Runtime

• Sweep line status updates: O(log n)


• Event queue operations: O(log n), as the total
number of stored events is  2n + k, and each
operation takes time
O(log(2n+k)) = O(log n2) = O(log n)
k = O(n2)

• There are O(n+k) events. Hence the total runtime


is O((n+k) log n)

1/22/15 CMPS 3130/6130 Computational Geometry 14

You might also like