0% found this document useful (0 votes)
6 views

Introduction and Line Segment Intersection

Uploaded by

wogodo3832
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Introduction and Line Segment Intersection

Uploaded by

wogodo3832
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Course Organization Geometric objects

Introduction Geometric relations


Line segment intersection Combinatorial complexity
Plane sweep Computational geometry

Introduction

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

Geometry: points, lines, ...

Plane (two-dimensional), R2
Space (three-dimensional), R3
Space (higher-dimensional), Rd

A point in the plane, 3-dimensional space, higher-dimensional


space.
p = (px , py ), p = (px , py , pz ), p = (p1 , p2 , . . . , pd )
A line in the plane: y = m · x + c; representation by m and c
A half-plane in the plane: y ≤ m · x + c or y ≥ m · x + c
Represent vertical lines? Not by m and c . . .

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

Geometry: line segments

A line segment pq is defined by its


two endpoints p and q:
(λ · px + (1 − λ ) · qx , λ · py + (1 − λ ) ·
qy )
where 0 ≤ λ ≤ 1
Line segments are assumed to be
closed = with endpoints, not open
Two line segments intersect if they
have some point in common. It is a
proper intersection if it is exactly one
interior point of each line segment

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

Polygons: simple or not


A polygon is a connected region of
the plane bounded by a sequence of
line segments interior
exterior
simple polygon
polygon with holes
convex polygon
non-simple polygon

The line segments of a polygon are


called its edges, the endpoints of
those edges are the vertices
Some abuse: polygon is only
boundary
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

Other shapes: rectangles, circles, disks

A circle is only the boundary, a disk


is the boundary plus the interior
Rectangles, squares, quadrants,
slabs, half-lines, wedges, . . .

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

Convexity

A shape or set is convex if for any


two points that are part of the
shape, the whole connecting line
segment is also part of the shape

Question: Which of the following


shapes are convex? Point, line
segment, line, circle, disk, quadrant?

For any subset of the plane (set of


points, rectangle, simple polygon),
its convex hull is the smallest convex
set that contains that subset

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

Relations: distance, intersection, angle

The distance between two points is


generally the Euclidean distance:
p
(px − qx )2 + (py − qy )2
p
Another option: the Manhattan (px − qx )2 + (py − qy )2 )
distance:
|px − qx | + |py − qy |
|py − qy |
Question: What is the set of points
at equal Manhattan distance to some |px − qx |
point?

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

Relations: distance, intersection, angle

The distance between two geometric objects other than points


usually refers to the minimum distance between two points that
are part of these objects

Question: How can the distance between two line segments be


realized?

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

Relations: distance, intersection, angle

The intersection of two geometric


objects is the set of points (part of
the plane, space) they have in
common

Question 1: How many intersection


points can a line and a circle have?
Question 2: What are the possible
outcomes of the intersection of a
rectangle and a quadrant?

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

Relations: distance, intersection, angle

Question 3: What is the maximum


number of intersection points of a
line and a simple polygon with 10
vertices (trick question)?

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

Relations: distance, intersection, angle

Question 4: What is the maximum


number of intersection points of a
line and a simple polygon boundary
with 10 vertices (still a trick
question)?

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

Description size

A point in the plane can be y =m·x+c


represented using two reals
A line in the plane can be
represented using two reals and a false, m, c
Boolean (for example)
A line segment can be represented by
two points, so four reals
A circle (or disk) requires three reals x=c
to store it (center, radius)
A rectangle requires four reals to
store it true, .., c

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

Description size

A simple polygon in the plane can be represented using 2n reals if


it has n vertices (and necessarily, n edges)
A set of n points requires 2n reals
A set of n line segments requires 4n reals

A point, line, circle, . . . requires O(1), or constant, storage.


A simple polygon with n vertices requires O(n), or linear, storage

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

Computation time

Any computation (distance, intersection) on two objects of O(1)


description size takes O(1) time!

Question: Suppose that a simple polygon with n vertices is given;


the vertices are given in counterclockwise order along the
boundary. Give an efficient algorithm to determine all edges that
are intersected by a given line.
How efficient is your algorithm? Why is your algorithm efficient?

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

Convex hull problem (Advanced Algorithms)

Give an algorithm that computes the


convex hull of any given set of n points in
the plane efficiently
Question 1: What is the input size?
Question 2: Why can’t we expect to do
any better than O(n) time?
Question 3: Is there any hope of finding
an O(n) time algorithm?
Question 4: What’s the optimal running
time?
Read Chapter 1 of [BCKO] today!

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

Computational geometry scope

In computational geometry, problems on input with more than


constant description size are the ones of interest

Computational geometry (theory): Study of geometric problems on


geometric data, and how efficient geometric algorithms that solve
them can be

Computational geometry (practice): Study of geometric problems


that arise in various applications and how geometric algorithms can
help to solve well-defined versions of such problems

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

Computational geometry theory

smallest enclosing circle


Computational geometry (theory):
Classify abstract geometric problems
into classes depending on how
closest pair
efficiently they can be solved

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

Computational geometry practice

Application areas that require geometric algorithms are computer


graphics, motion planning and robotics, geographic information
systems, CAD/CAM, statistics, physics simulations, databases,
games, multimedia retrieval, . . .

Computing shadows from virtual light sources


Spatial interpolation from groundwater pollution
measurements
Computing a collision-free path between obstacles
Computing similarity of two shapes for shape database
retrieval

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

Computational geometry history

Early 70s: First attention for geometric problems from algorithms


researchers
1976: First PhD thesis in computational geometry (Michael
Shamos)
1985: First Annual ACM Symposium on Computational Geometry.
Also: first textbook
1996: CGAL: first serious implementation effort for robust
geometric algorithms
1997: First handbook on computational geometry (second one in
2000)

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

Line segment intersection

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

Map layers

In a geographic information system


(GIS) data is stored in separate
layers

A layer stores the geometric


information about some theme, like
land cover, road network,
municipality boundaries, red fox
habitat, . . .

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

Map overlay

Map overlay is the combination of


two (or more) map layers

It is needed to answer questions like:


What is the total length of
roads through forests?
What is the total area of corn
fields within 1 km from a river?

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

Map overlay

To solve map overlay questions, we


need (at the least) intersection
points from two sets of line segments
(possibly, boundaries of regions)

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

The (easy) problem

Let’s first look at the easiest version


of the problem:
Given a set of of n line segments in
the plane, find all intersection points
efficiently

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

An easy, optimal algorithm?

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

Question: Why can we say that this algorithm is optimal?

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

Output-sensitive algorithm

The asymptotic running time of an


algorithm is always input-sensitive
(depends on n)

We may also want the running time


to be output-sensitive: if the output
is large, it is fine to spend a lot of
time, but if the output is small, we
want a fast algorithm

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

Intersection points in practice

Question: How many intersection


points do we typically expect in our
application?

If this number is k, and if k = O(n),


it would be nice if the algorithm runs
in O(n log n) time

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

First attempt

Observation: Two line segments


y
can only intersect if their y-spans
have an overlap

So, how about only testing pairs of


x
line segments that intersect in the
y-projection?

1-D problem: Given a set of intervals


on the real line, find all partly s1 s2 s3 s4 s5 s6
overlapping pairs
(s1 , s2 ), (s4 , s6 ), (s5 , s6 )

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Motivation: Map overlay
Introduction Problem
Line segment intersection Output-sensitive algorithms
Plane sweep Some attempts

Second attempt

Refined observation: Two line


segments can only intersect if their
y-spans have an overlap, and they
are adjacent in the x-order at that
y-coordinate (they are horizontal
neighbors)

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Plane sweep

The plane sweep technique: Imagine a horizontal line


passing over the plane from top to bottom, solving the
problem as it moves

The sweep line stops and the algorithm computes at


certain positions ⇒ events
The algorithm stores the relevant situation at the current
position of the sweep line ⇒ status
The algorithm knows everything it needs to know above
the sweep line, and found all intersection points

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

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

Sweep and status

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

Status and events

The status of this particular plane sweep algorithm, at the


current position of the sweep line, is the set of line segments
intersecting the sweep line, ordered from left to right

The events occur when the status changes, and when output
is generated

event ≈ interesting y-coordinate

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4

s5 add s1
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4

s5 add s2 after s1
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4
add s3 between s1
s5 and s2
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4

s5 add s4 before s1
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4
report intersection
s5 (s1 , s2 ); swap s1
and s3
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4
remove s2
s5
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4
remove s1
s5
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4

s5 add s5
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

s1

s3 s2

s4
report intersection
s5 (s3 , s4 ); swap s3
and s4
s6
s7

s8

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

. . . and so on . . .

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

When do the events happen? When the sweep line is

at an upper endpoint of a line segment


at a lower endpoint of a line segment
at an intersection point of a line segment

At each type, the status changes; at the third type output is


found too

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Assume no degenerate cases

We will at first exclude degenerate cases:


No two endpoints have the same
y-coordinate
No more than two line segments
intersect in a point
...

Question: Are there more degenerate


cases?

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event list and status structure

The event list is an abstract data structure that stores all


events in the order in which they occur

The status structure is an abstract data structure that


maintains the current status

Here: The status is the subset of currently intersected line


segments in the order of intersection by the sweep line

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
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

Upper endpoint: search, and insert


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

Upper endpoint: search, and insert


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 s9 s4 s5 s6 s7 s8
s9 s3

s1 s2 s5 s6 s8
s3 s4
s9 s7

Upper endpoint: search, and insert


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

Sweep line reaches lower endpoint of a line segment: delete


from the status structure

Sweep line reaches intersection point: swap two leaves in the


status structure (and update information on the search paths)

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Finding events

Before the sweep algorithm starts, we know all upper


endpoint events and all lower endpoint events

But: How do we know intersection point events???


(those we were trying to find . . .)

Recall: Two line segments can only intersect if they are


horizontal neighbors

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

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!!!

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event list

The event list must be a balanced binary search tree, because


during the sweep, we discover new events that will happen
later

We know upper endpoint events and lower endpoint events


beforehand; we find intersection point events when the
involved line segments become horizontal neighbors

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Structure of sweep algorithm

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)

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event handling

If the event is an upper endpoint


event, and s is the line segment that
starts at p:

1 Search with p in T, and insert s p


2 If s intersects its left neighbor in
T, then determine the s
intersection point and insert it Q
3 If s intersects its right neighbor
in T, then determine the
intersection point and insert it Q

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event handling

If the event is a lower endpoint


event, and s is the line segment that
ends at p:
s
1 Search with p in T, and delete s
p
2 Let sl and sr be the left and
right neighbors of s in T (before
deletion). If they intersect
below the sweep line, then insert
their intersection point as an
event in Q

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event handling

If the event is an intersection point


event where s and s0 intersect at p: s s0
1 ... p
2 ...
3 ...
4 ...

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event handling

If the event is an intersection point


event where s and s0 intersect at p: s s0
1 Exchange s and s0 in T p
2 ...
3 ...
4 ...

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event handling

If the event is an intersection point


event where s and s0 intersect at p:

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 ...

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

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 ...

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

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

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Event handling

Can it be that new


horizontal neighbors already
s0 intersected above the sweep
s line?

p Can it be that we insert a


newly detected intersection
point event, but it already
occurs in Q?

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Efficiency

How much time to handle an event?

At most one search in T and/or one insertion, deletion, or


swap
At most twice finding a neighbor in T

At most one deletion from and two insertions in Q

Since T and Q are balanced binary search trees, handling an


event takes only O(log n) time

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Efficiency

How many events?

2n for the upper and lower endpoints


k for the intersection points, if there are k of them

In total: O(n + k) events

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Efficiency

Initialization takes O(n log n) time (to put all upper and lower
endpoint events in Q)

Each of the O(n + k) events takes O(log n) time

The algorithm takes O(n log n + k log n) time


If k = O(n), then this is O(n log n)

Note that if k is really large, the brute force O(n2 ) time


algorithm is more efficient

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Efficiency

Question: How much storage does the algorithm take?

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep 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?

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Degenerate cases

How do we deal with degenerate cases?

For two different events with the same y-coordinate, we treat


them from left to right ⇒ the “upper” endpoint of a
horizontal line segment is its left endpoint

Geometric Algorithms Lecture 1: Introduction and line segment intersection


Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

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

Question: How do we handle this multi-event?


Geometric Algorithms Lecture 1: Introduction and line segment intersection
Course Organization Introduction
Introduction Events, status, structures
Line segment intersection Event handling
Plane sweep Efficiency

Conclusion

For every sweep algorithm:


Define the status
Choose the status structure and the event list
Figure out how events must be handled (with sketches!)
To analyze, determine the number of events and how
much time they take

Then deal with degeneracies

Geometric Algorithms Lecture 1: Introduction and line segment intersection

You might also like