Explained Nicely
Transcript of Explained Nicely
-
8/6/2019 Explained Nicely
1/59
MotivationTriangulating a polygon
Triangulating a polygon
Geometric Algorithms
Lecture 2: Triangulating a polygon
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
2/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
Polygons and visibility
Two points in a simple polygon can see each other if theirconnecting line segment is in the polygon
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
3/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
Art gallery problem
Art Galley Problem: How many cameras are needed toguard a given art gallery so that every point is seen?
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
4/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
Art gallery problem
In geometry terminology: How many points are needed in asimple polygon with n vertices so that every point in thepolygon is seen?
The optimization problem is computationally difficult
Art Galley Theorem: n/3 cameras are occasionallynecessary but always sufficient
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
5/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
Triangulation, diagonal
Why are n/3 always enough?
Assume polygon P is triangulated: a
decomposition of P into disjointtriangles by a maximal set ofnon-intersecting diagonals
Diagonal of P: open line segment
that connects two vertices of P andfully lies in the interior of P
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
6/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
A triangulation always exists
Lemma: A simple polygon with n verticescan always be triangulated, and alwayshave n 2 triangles
Proof: Induction on n. If n = 3, it istrivial
Assume n > 3. Consider the leftmostvertex v and its two neighbors u and w.Either uw is a diagonal (case 1), or part of
the boundary of P is in uvw (case 2)
Choose the vertex t in uvw farthest fromthe line through u and w, then vt must bea diagonal
v
v
u
u
w
w
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
7/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
A triangulation always exists
In case 1, uw cuts the polygon into a triangle and a simplepolygon with n 1 vertices, and we apply induction
In case 2, vt cuts the polygon into two simple polygons withm and nm + 2 vertices 3 m n 1, and we also applyinduction
By induction, the two polygons can be triangulated usingm 2 and nm + 2 2 = nm triangles. So the originalpolygon is triangulated using m 2 + nm = n 2triangles
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
8/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
A 3-coloring always exists
Observe: the dual of a triangulated simplepolygon is a tree
Lemma: The vertices of a triangulatedsimple polygon can always be 3-colored
Proof: Induction. True for a triangle
Every tree has a leaf. Remove the
corresponding triangle from thetriangulated polygon, color its vertices, addthe triangle back, and let the extra vertexhave the color different from its neighbors
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
9/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
A 3-coloring always exists
Geometric Algorithms Lecture 2: Triangulating a polygon
Vi ibili i l
-
8/6/2019 Explained Nicely
10/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
n/3 cameras are enough
For a 3-colored, triangulated simple
polygon, one of the color classes is used byat most n/3 colors. Place the cameras atthese vertices
This argument is called
the pigeon-hole principle
Geometric Algorithms Lecture 2: Triangulating a polygon
Vi ibilit i l
-
8/6/2019 Explained Nicely
11/59
MotivationTriangulating a polygon
Visibility in polygonsTriangulationProof of the Art gallery theorem
n/3 cameras are enough
Question: Why does the proof fail when the polygon hasholes?
Geometric Algorithms Lecture 2: Triangulating a polygon
Towards an efficient algorithm
-
8/6/2019 Explained Nicely
12/59
MotivationTriangulating a polygon
gPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Two-ears for triangulation
Using the two-ears theorem:(an ear consists of three consecutivevertices u,v,w where uw is a diagonal)
Find an ear, cut it off with a diagonal,triangulate the rest iteratively
Question: Why does every simple polygon
have an ear?
Question: How efficient is this algorithm?
Geometric Algorithms Lecture 2: Triangulating a polygon
Towards an efficient algorithm
-
8/6/2019 Explained Nicely
13/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Overview
A simple polygon is y-monotone iff anyhorizontal line intersects it in a connectedset (or not at all)
Use plane sweep to partition the polygoninto y monotone polygons
Then triangulate each y-monotone polygon
Geometric Algorithms Lecture 2: Triangulating a polygon
Towards an efficient algorithm
-
8/6/2019 Explained Nicely
14/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Monotone polygons
A y-monotone polygon has a top vertex, a
bottom vertex, and two y-monotone chainsbetween top and bottom as its boundary
Any simple polygon with one top vertexand one bottom vertex is y-monotone
Geometric Algorithms Lecture 2: Triangulating a polygon
M i iTowards an efficient algorithmP i i i i i
-
8/6/2019 Explained Nicely
15/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Vertex types
What types of vertices does ageneral simple polygon have?
start
stop
split
merge
regular. . . imagining a sweep line going topto bottom
start
merge regular
split
end
Geometric Algorithms Lecture 2: Triangulating a polygon
M ti tiTowards an efficient algorithmP titi i i t t i
-
8/6/2019 Explained Nicely
16/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Find diagonals from each mergevertex down, and from each split
vertex up
A simple polygon with no split ormerge vertices can have at most onestart and one stop vertex, so it is
y-monotone
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
17/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Find diagonals from each mergevertex down, and from each split
vertex up
A simple polygon with no split ormerge vertices can have at most onestart and one stop vertex, so it is
y-monotone
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
18/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
explored
unexplored
explored
unexplored
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
19/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Where can a diagonal from asplit vertex go?
Perhaps the upper endpoint ofthe edge immediately left of
the merge vertex?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
20/59
MotivationTriangulating a polygon
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Where can a diagonal from asplit vertex go?
Perhaps the upper endpoint ofthe edge immediately left of
the merge vertex?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
21/59
Triangulating a polygong p
Triangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Where can a diagonal from asplit vertex go?
Perhaps the upper endpoint ofthe edge immediately left of
the merge vertex?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
22/59
Triangulating a polygong p
Triangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Where can a diagonal from asplit vertex go?
Perhaps the last vertex passedin the same component?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
23/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Where can a diagonal from asplit vertex go?
Perhaps the last vertex passedin the same component?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTowards an efficient algorithmPartitioning into monotone pieces
-
8/6/2019 Explained Nicely
24/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Sweep ideas
Where can a diagonal from asplit vertex go?
Perhaps the last vertex passedin the same component?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationT i l i l
Towards an efficient algorithmPartitioning into monotone piecesT i l i l
-
8/6/2019 Explained Nicely
25/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Status of sweep
The status is the set of edgesintersecting the sweep line thathave the polygon to theirright, sorted from left to right,and each with their helper: thelast vertex passed in that
component
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationT i l ti l
Towards an efficient algorithmPartitioning into monotone piecesT i l ti t l
-
8/6/2019 Explained Nicely
26/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Helpers of edges
The helper for an edge e thathas the polygon right of it,
and a position of the sweepline, is the lowest vertex vabove the sweep line such thatthe horizontal line segmentconnecting e and v is inside
the polygon
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
27/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Status structure, event list
The status structure stores all edges that have the polygon tothe right, with their helper, sorted from left to right in theleaves of a balanced binary search tree
The events happen only at the vertices: sort them byy-coordinate and put them in a list (or array, or tree)
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
28/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Main algorithm
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
29/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Event handling
Start vertex v:
Insert the counterclockwiseincident edge in T with v as thehelper
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
30/59
Triangulating a polygon Triangulating a monotone polygonTriangulating a simple polygon
Event handling
End vertex v:Delete the clockwise incidentedge and its helper from T
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
31/59
g g p yg g g p ygTriangulating a simple polygon
Event handling
Regular vertex v:
If the polygon is right of the twoincident edges, then replace theupper edge by the lower edge inT, and make v the helper
If the polygon is left of the twoincident edges, then find the
edge e directly left of v, andreplace its helper by v
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
32/59
g g p yg g g p ygTriangulating a simple polygon
Event handling
Merge vertex v:
Remove the edge clockwisefrom v from T
Find the edge e directly left ofv, and replace its helper by v
e
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
33/59
Triangulating a simple polygon
Event handling
Split vertex v:
Find the edge e directly left of
v, and choose as a diagonal theedge between its helper and v
Replace the helper of e by v
Insert the edge counterclockwise
from v in T, with v as its helper
e
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygon
-
8/6/2019 Explained Nicely
34/59
Triangulating a simple polygon
Efficiency
Sorting all events by y-coordinate takes O(n log n) time
Every event takes O(log n) time, because it only involvesquerying, inserting and deleting in T
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonT i l ti i l l
-
8/6/2019 Explained Nicely
35/59
Triangulating a simple polygon
Degenerate cases
Question: Which degenerate cases arise in this algorithm?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriang lating a simple pol gon
-
8/6/2019 Explained Nicely
36/59
Triangulating a simple polygon
Representation
A simple polygon with somediagonals is a subdivision use a DCEL
Question: How manydiagonals may be chosen to
the same vertex?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
37/59
Triangulating a simple polygon
More sweeping
With an upward sweep in eachsubpolygon, we can find a
diagonal down from everymerge vertex (which is a splitvertex for an upward sweep!)
This makes all subpolygons
y-monotone
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
38/59
Triangulating a simple polygon
Result
Theorem: A simple polygon with n vertices can bepartitioned into y-monotone pieces in O(n log n) time
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
39/59
Triangulating a simple polygon
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
40/59
Triangulating a simple polygon
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
41/59
g g p p yg
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
42/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
43/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
44/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
45/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
46/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
47/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
48/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
-
8/6/2019 Explained Nicely
49/59
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
50/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
51/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
-
8/6/2019 Explained Nicely
52/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
T i l i l
-
8/6/2019 Explained Nicely
53/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
T i l i l
-
8/6/2019 Explained Nicely
54/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
T i l i l
-
8/6/2019 Explained Nicely
55/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithmPartitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
T i l ti t l
-
8/6/2019 Explained Nicely
56/59
Triangulating a monotone polygon
How to triangulate ay-monotone polygon?
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithm
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Th l ith
-
8/6/2019 Explained Nicely
57/59
The algorithm
Sort the vertices top-to-bottom by a merge of the twochains
Initialize a stack. Pop the first two vertices
Take the next vertex v, and triangulate as much aspossible, top-down, while popping the stack
Push v onto the stack
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithm
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Result
-
8/6/2019 Explained Nicely
58/59
Result
Theorem: A simple polygon with n vertices can bepartitioned into y-monotone pieces in O(n log n) time
Theorem: A monotone polygon with n vertices can betriangulated O(n) time
Can we immediately conclude:
A simple polygon with n vertices can be triangulated
O(n log n) time ???
Geometric Algorithms Lecture 2: Triangulating a polygon
MotivationTriangulating a polygon
Towards an efficient algorithm
Partitioning into monotone piecesTriangulating a monotone polygonTriangulating a simple polygon
Result
-
8/6/2019 Explained Nicely
59/59
Result
We need to argue that all monotone polygons together thatwe will triangulate have O(n) vertices
Initially we had n edges. We add at most n 3 diagonals in
the sweeps. So all monotone polygons together have at most2n 3 edges, and therefore at most 2n 3 vertices
Hence we can conclude that triangulating all monotonepolygons together takes only O(n) time
Theorem: A simple polygon with n vertices can betriangulated O(n log n) time
Geometric Algorithms Lecture 2: Triangulating a polygon