CS6100: Topics in Design and Analysis of Algorithms Guarding and Triangulating Polygons John Augustine CS6100 (Even 2012): Guarding and Triangulating Polygons
The Art Gallery Problem A simple polygon is a region enclosed by a single closed polygonal chain that does not intersect itself. Models 2D spaces such as floor plans. Given a simple polygon P with n vertices, place a small number of guards inside P so that it is completely monitored. I.e., for any point p inside P , there must be a guard positioned at g such that line segment pq is completely inside P . Computing the optimum (i.e., minimum) is NP-hard. CS6100 (Even 2012): Guarding and Triangulating Polygons 1
Triangulation A convex polygon only needs one guard! So, if we can decompose P into convex pieces, we need one per convex piece. A diagonal of P is a line segment that connects two vertices of P and is contained in the interior of P . A triangulation is a decomposition of P into triangles be a maximal number of non-intersecting diagonals. Theorem 1. Any simple polygon P with n vertices admits a triangulation and any triangulation has ( n − 2) triangles. CS6100 (Even 2012): Guarding and Triangulating Polygons 2
w w v ′ v v u u Proof Sketch. First we show that a diagonal always exists. (See figures above.) Then, we can always cut along such a diagonal, thereby decomposing P into two smaller polygons that we can induct on to show both claims. Assume for now that a triangulation of P is given. Do we really need n − 2 guards? Can we do better? CS6100 (Even 2012): Guarding and Triangulating Polygons 3
Back to the Art Gallery Problem A 3-colouring of a triangulated polygon P is an assignment of one of three distinct colours to each vertex such that any two vertices connected by an edge or a diagonal are assigned different colours. The three vertices of any triangle will be Note. assigned different colours. How can we show that ⌊ n/ 3 ⌋ guards suffice if ∃ 3-colouring? µ ν ? The dual graph of a triangulated polygon P is a graph G = ( V, E ) such that V is the set of ( n − 2) triangles and edges connect two triangles that share an edge. We use DFS on the dual graph to 3-colour P . CS6100 (Even 2012): Guarding and Triangulating Polygons 4
Vertices of all triangles corresponding to Invariant. dual graph nodes traversed are 3-colored. Start DFS from any node. 3-Colour the vertices of corresponding triangle. Consider any subsequent edge traversed. It goes through a diagonal d and enters a new triangle. The ends of d are already coloured and the third vertex of the newly entered triangle can only be coloured by one colour. The good news is that the invariant is maintained. Theorem 2 (Art Gallery Theorem) . To guard a simple polygon with n vertices, ⌊ n/ 3 ⌋ guards are sufficient and sometimes necessary. ⌊ n / 3 ⌋ prongs CS6100 (Even 2012): Guarding and Triangulating Polygons 5
Overview of Approach Theorem 3. We can compute the positions of the ⌊ n/ 3 ⌋ guards for a simple polygon P with n vertices in O ( n log n ) time. The birds eye view of the algorithm is as follows. 1. Decompose P into y -monotone pieces. (Definition pending.) 2. Triangulate each y -monotone piece. This gives a triangulation of P . 3. 3-colour the vertices of P using the triangulation of P . 4. Find the colour used least and place guards on vertices of that colour. CS6100 (Even 2012): Guarding and Triangulating Polygons 6
Decomposing P into y -monotone pieces A y -monotone polygon is a simple polygon such that its intersection with any line perpendicular to the y -axis is connected. y -axis To triangulate P , we first partition P into y -monotone sub-polygons (in O ( n log n ) time and then triangulate the y -monotone pieces (again, in O ( n log n ) time. CS6100 (Even 2012): Guarding and Triangulating Polygons 7
Classification of Vertices A vertex at which, as we walk along the edges, the direction of the edges change from downward to upward or vice versa is called a turn vertex . A vertex at which the direction does not change is called a regular vertex . The following figure illustrates 4 types of turn vertices. v 5 v 3 v 4 e 4 e 3 e 5 = start vertex v 6 e 6 = end vertex e 2 v 7 v 9 = regular vertex e 7 v 2 v 8 e 8 v 1 e 1 = split vertex e 9 e 15 e 14 = merge vertex v 14 v 10 v 15 e 13 e 10 e 12 e 11 v 12 v 13 v 11 Lemma 1. A simple polygon is y -monotone if it does not contain any split or merge vertex. The proof is left as an exercise. While this lemma is easy to “see,” a formal proof needs a bit of care. CS6100 (Even 2012): Guarding and Triangulating Polygons 8
Plane Sweep Method Let v 1 be the rightmost vertex in P . Traverse the edges of P starting from v 1 so that the polygon is always to your left. In so doing, denote the i th vertex you encounter as v i for all 1 < i ≤ n . Denote edge v i v i +1 as e i for 1 ≤ i < n . Denote edge v n v 1 as e n . Let Left be the set of edges of P such that the polygon lies to its right. We sweep a line ℓ from top to bottom. The status of the sweep line ℓ at any given time is the edges in Left that ℓ intersects. They are stored in L → R order in a balanced binary tree. The events are the vertices of P and since they are known up front, they can be stored in an array sorted according to the descending order of y coordinates. CS6100 (Even 2012): Guarding and Triangulating Polygons 9
Let e be an edge in the status of ℓ . We define the helper of e , denoted helper ( e ) , as the lowest vertex above ℓ such that the horizontal line segment connecting the vertex to e lies inside P . helper ( e ) may be the upper endpoint of e . Note: (The figure below shows the helper of an edge e j .) helper ( e j ) e j e k ℓ v i e i e i − 1 Given Lemma 1, we can focus our efforts on eliminating merge and split vertices. CS6100 (Even 2012): Guarding and Triangulating Polygons 10
Pseudocode from BCKO 1 Algorithm M AKE M ONOTONE ( P ) Input. A simple polygon P stored in a doubly-connected edge list D . Output. A partitioning of P into monotone subpolygons, stored in D . 1. Construct a priority queue Q on the vertices of P , using their y -coordinates as priority. If two points have the same y -coordinate, the one with smaller x -coordinate has higher priority. Initialize an empty binary search tree T . 2. while Q is not empty 3. 4. do Remove the vertex v i with the highest priority from Q . 5. Call the appropriate procedure to handle the vertex, depending on its type. H ANDLE S TART V ERTEX ( v i ) Insert e i in T and set helper ( e i ) to v i . 1. H ANDLE E ND V ERTEX ( v i ) if helper ( e i − 1 ) is a merge vertex 1. then Insert the diagonal connecting v i to helper ( e i − 1 ) in D . 2. 3. Delete e i − 1 from T . H ANDLE S PLIT V ERTEX ( v i ) 1. Search in T to find the edge e j directly left of v i . 2. Insert the diagonal connecting v i to helper ( e j ) in D . helper ( e j ) ← v i 3. Insert e i in T and set helper ( e i ) to v i . 4. 1 Computational Geometry: Algorithms and Applications, by de Berg, Cheong, van Krevald, and Overmars. CS6100 (Even 2012): Guarding and Triangulating Polygons 11
H ANDLE M ERGE V ERTEX ( v i ) if helper ( e i − 1 ) is a merge vertex 1. 2. then Insert the diagonal connecting v i to helper ( e i − 1 ) in D . 3. Delete e i − 1 from T . 4. Search in T to find the edge e j directly left of v i . if helper ( e j ) is a merge vertex 5. then Insert the diagonal connecting v i to helper ( e j ) in D . 6. helper ( e j ) ← v i 7. H ANDLE R EGULAR V ERTEX ( v i ) 1. if the interior of P lies to the right of v i then if helper ( e i − 1 ) is a merge vertex 2. then Insert the diagonal connecting v i to helper ( e i − 1 ) in D . 3. 4. Delete e i − 1 from T . Insert e i in T and set helper ( e i ) to v i . 5. else Search in T to find the edge e j directly left of v i . 6. if helper ( e j ) is a merge vertex 7. then Insert the diagonal connecting v i to helper ( e j ) in D . 8. 9. helper ( e j ) ← v i Lemma 2. Algorithm MakeMonotone correctly adds a set of non-intersecting diagonals that partitions P into monotone subpolygons. Theorem 4. A simple polygon with n vertices can be partioned into y -monotone polygons in O ( n log n ) time with an algorithm that uses O ( n ) storage. Proofs are left as exercises. CS6100 (Even 2012): Guarding and Triangulating Polygons 12
e k v i e j v m diagonal will be added when the sweep line reaches v m v 5 v 3 v 4 e 4 e 5 e 3 v 6 e 6 e 2 v 1 v 7 v 9 v 2 e 7 e 1 v 8 e 8 e 15 e 9 e 14 v 14 v 10 e 13 v 15 e 10 e 11 v 12 e 12 v 11 v 13 CS6100 (Even 2012): Guarding and Triangulating Polygons 13
Triangulating a Monotone Polygon Given a y -monotone polygon P , we want to triangulate it. We assume that P is given as a sequence of vertices ordered anticlockwise. From the given sequence, we can order the vertices in decreasing order of their y -coordinates. How? Once ordered, we pass through the vertices top → bottom. As the algorithm progresses, a (connected) portion of P will be untriangulated, while the rest is triangulated. Even though we might have passed some of the vertices, they may still be on the boundary of the untriangulated part of P . CS6100 (Even 2012): Guarding and Triangulating Polygons 14
Recommend
More recommend