Computational Geometry
Computational Geometry
Chapter
Chapter 6
6
Point Location
Point Location
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 1
Problem Definition
Problem Definition
Preprocess a planar map S.Given a query point p, report
the face of S containing p.g p A S
Goal: O(n)-size data structure that enables O(log n) query time.
Application: Which state is Baltimore located in?
p D E G F C B Answer: Maryland
Trivial Solution: O(n) query time, where n is the complexity of the map.
Naïve Solution
Naïve Solution
Draw vertical lines through allthe vertices of the subdivision. Store the x-coordinates of the vertices in an ordered binary tree.
Within each slab, sort the segments separately along y. Query time: O(log n)
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 3
Query time: O(log n). Problem: Too delicate
subdivision, of size (n2) in
the worst case.
(Give such an example!)
The Trapezoidal Map
The Trapezoidal Map
Construct a bounding box. Assume general position: unique x coordinates.g p q
Extend upward and downward the vertical line from each vertex until it touches another segment.
This works
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 4
also for noncrossing line
Properties
Properties
Contains triangles and trapezoids.
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 5
and trapezoids.
Each trapezoid or triangle is determined:
By two vertices that define vertical sides; and By two segments that define nonvertical sides.
A refinement of the original subdivision.
Notation
Notation
Every trapezoid (or triangle) is defined by Left(): a segment endpoint (right or left); Right(): a segment endpoint (right or left);
Top(): a segment;
Complexity
Complexity
Theorem (linear complexity):A trapezoidal map of n segments contains at most 6n+4 ertices contains at most 6n+4 vertices and at most 3n+1 faces.
Proof: 1. Vertices: 2n + 4n + 4 = 6n + 4 i i l t i b i i l t i b
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 7
2
2. . Faces: Count Left().
2n + n + 1 = 3n + 1
original extensions box original extensions box
left e.p. right e.p. box left e.p. right e.p. box
Question: Question:
Why does the proof Why does the proof hold for “degenerate” hold for “degenerate” situations?
situations?
Map Data Structure
Map Data Structure
Possibly by DCEL.An alternative: An alternative:
For each trapezoid store: The vertices that define its
right and left sides;
The top and bottom segments; The (up to two) neighboring
trapezoids on right and left; NoteNote: Computing any: Computing any
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 8
trapezoids on right and left; (Optional) The neighboring
trapezoids from above and below. This number might be linear in n, so only the leftmost of these trapezoids is stored.
Note
Note: Computing any : Computing any trapezoid from the trapezoid from the trapezoidal structure trapezoidal structure can be done in can be done in constant time. constant time.
Search Structure: Branching Rules
Search Structure: Branching Rules
Query point q, search-structure node s. s is a segment endpoint:
q is to the right of s: go right; q is to the left of s: go left;
s is a segment:
q is below s: go right; q is above s: go left;
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 9
Q1
P1 Q2
The DAG Search Structure
The DAG Search Structure
B A D E H J K P3 Q3 S3 P3 S3 C S1 P2 A S S Q3 S S C F G J P1 P2 Q1 Q2 S1 S2 B C S3 S2 D E F G D H S2 S3 J KQ1
P1 Q2
Using the Search Structure
Using the Search Structure
B A D E H J K P3 Q3 S3 P3 S3 C S1 P2 A S S Q3 S S C F G J P1 P2 Q1 Q2 S1 S2
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 11
B C S3 S2 D E F G D H S2 S3 J K
Search Structure: Construction
Search Structure: Construction
Find a Bounding Box. Randomly permute the segments.
Insert the segments one by one into the map.
Update the map and search structure in each insertion. The size of the map is (n).
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 12
p ( )
(This was proven earlier.) The size of the search
structure depends on the order of insertion.
Updating the Structures (High Level)
Updating the Structures (High Level)
Find in the existing structure the facethat contains the left endpoint of the new segment (*)
of the new segment. ( )
Find all other trapezoids
intersected by this segment by moving to the right. (In each move choose between two options: Up or Down.)
Update the map Miand the
h D
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 13
search structure Di.
(*) Note
(*) Note: Since endpoints may : Since endpoints may be shared by segments, we be shared by segments, we need to consider its segment need to consider its segment while searching.
while searching.
Update: Simple Case
Update: Simple Case
The segment is containedentirely in one trapezoid. In M : Split the trapezoid into
Mi-1
In Mi-1: Split the trapezoid into four trapezoids.
In Di-1: The leaf will be replaced by a subtree. Everything is done in O(1) ti Pi Q A B D T Qi Pi time. Qi Si A C Pi
General Case: The ith
segment intersects with k >1 trape oids
Update
Update M
M: General Case
: General Case
ki>1 trapezoids. Split trapezoids. Merge trapezoids that
can be united.
Total update time: O(ki).
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 15
Updating
Updating D
D: Split
: Split
Each inner trapezoid in Di-1 is replaced b Si is replaced by: Each outer (e.g., left) i A B PCenter for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 16
( g , ) trapezoid in Di-1 is replaced by: Pi A Si B C
Updating
Updating D
D: Merge
: Merge
C E Leaves are eliminated and
replaced by one common leaf
Si Si Si A B D E F K G H Si L replaced by one common leaf.
Total update time: O(ki).
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 17
C E B D F K H A G L
Construction: Worst
Construction: Worst--Case Analysis
Case Analysis
Each segment adds trees of depth at most (4-1=) 3,so the depth of Dp iiis at most 3i.
Query time (depth of Di): O(i), (i) in the worst case. The ithsegment, s
i, may intersect with O(i) trapezoids
((i) in the worst case)!
The size of D and its construction time are then bounded from above by
n .
n in
O
i
O
1 2)
(
)
(
Construction: Worst
Construction: Worst--Case Analysis
Case Analysis
(cont.)
(cont.)
Worst-case example:
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 19
Construction: Worst
Construction: Worst--Case Analysis
Case Analysis
(cont.)
(cont.)
Worst-case example:
O( O(nn))
Center for Graphics and Geometric Computing, Technion
Construction: Worst
Construction: Worst--Case Analysis
Case Analysis
(cont.)
(cont.)
Worst-case example:
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 21
The size of D and its construction time is
in the worst case.
n n i n in
n
1 2 2 2 1)
(
)
(
)
1
(
Average
Average--Case Analysis
Case Analysis
We first look for the expected depth of D. q: A point, to be searched for in D. pi: The probability that a new vertex was created in the path leading to q in the ithiteration.
Compute piby backward analysis:
q(Mi-1): The trapezoid containing q in Mi-1. Since a new vertex was created (M ) (M ) Since a new vertex was created, q(Mi) q(Mi-1). Delete sifrom Mi.
Expected Depth of
Expected Depth of D
D
xi: The number of vertices created in the ith
iteration in the path leading to the leaf q.
The expected length of the path leading to q: q
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 23
The expected length of the path leading to q:
(
3
)
O
(
log
)
.
E
E
1 1 1 12 1
n i n i n i i i i n i ix
p
n
x
Expected Size of
Expected Size of D
D
Define an indicator ) 1 disappearsfrom if isremoved
( s Mi s
ki: Number of leaves created in the ithstep.
Si: The set of the first i segments. Average on s: otherwise 0 ) , ( s i ) ( ) ( ] [ E 1 1
s
s k Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 24
). 1 ( O analysis) backward (same |) | 4 ( ) , ( ) , ( ] [ E ) ( O 1
i i i i S s M i i S s M i i i M s s k i i i i Expected Size of
Expected Size of D
D (cont.)
(cont.)
ki-1: Number of internal nodes created in the ithstep.
Total size: leaves internal leaves internal ). ( O E ) ( O ) 1 ( E ) ( O 1 1 n k n k n n i i n i i
sCenter for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 25
Expected Construction Time of
Expected Construction Time of D
D
O
(
E(depth
))
O
(
E
[
k
])
n i i
)
log
(
))
1
(
)
(log
(
1 1n
n
O
O
i
O
n i i
Finding the first trapezoid The rest of the work in the ithstepHandling Degeneracies
Handling Degeneracies
What happens if two segment endpointshave the same x coordinate? Use a shearing
transformation:
Higher points will move more to the right. should be small enough so that this
transform will not change the order of two
y
y
x
y
x
Center for Graphics and Geometric Computing, Technion
Center for Graphics and Geometric Computing, Technion 27
g
points with different x coordinates.
In fact, there is no need to shear the plane. Comparison rules mimic the shearing. Prove: The entire algorithm remains correct.