Lecture 3: Art Gallery Problems and Polygon Triangulation

Similar documents
CS6100: Topics in Design and Analysis of Algorithms

Computational Geometry

Polygon Triangulation. (slides partially by Daniel Vlasic )

Polygon decomposition. Motivation: Art gallery problem

2 A Plane Sweep Algorithm for Line Segment Intersection

Polygon Partitioning. Lecture03

Polygon Triangulation. (slides partially by Daniel Vlasic )

CS 532: 3D Computer Vision 14 th Set of Notes

Lecture 4: Trees and Art Galleries

Computational Geometry [csci 3250]

Professor: Padraic Bartlett. Lecture 9: Trees and Art Galleries. Week 10 UCSB 2015

Solutions to problem set 1

Motivation: Art gallery problem. Polygon decomposition. Art gallery problem: upper bound. Art gallery problem: lower bound

Polygon Triangulation

CS 532: 3D Computer Vision 11 th Set of Notes

Orthogonal art galleries with holes: a coloring proof of Aggarwal s Theorem

MISCELLANEOUS SHAPES

Projects & Polygon Triangulation

Visibility: Finding the Staircase Kernel in Orthogonal Polygons

Line segment intersection. Family of intersection problems

Visibility Analysis for Video Surveillance

Connected Components of Underlying Graphs of Halving Lines

Art Gallery, Triangulation, and Voronoi Regions

Computational Geometry

Week 2 Polygon Triangulation

The Art Gallery Problem: An Overview and Extension to Chromatic Coloring and Mobile Guards

Ma/CS 6b Class 26: Art Galleries and Politicians

Visibilty: Finding the Staircase Kernel in Orthogonal Polygons

AMS 345/CSE 355 Computational Geometry

Computing intersections in a set of line segments: the Bentley-Ottmann algorithm

GEOMETRIC SEARCHING PART 1: POINT LOCATION

January 10-12, NIT Surathkal Introduction to Graph and Geometric Algorithms

On Merging Straight Skeletons

Line Arrangements. Applications

CMSC 754 Computational Geometry 1

CMSC 754 Computational Geometry 1

Discrete Mathematics I So Practice Sheet Solutions 1

The Geometry of Carpentry and Joinery

Partitioning Orthogonal Polygons by Extension of All Edges Incident to Reflex Vertices: lower and upper bounds on the number of pieces

The SUMO Speaker Series for Undergraduates. The Art Gallery Problem

[Ba] Bykat, A., Convex hull of a finite set of points in two dimensions, Info. Proc. Lett. 7 (1978),

The Art Gallery Problem

Computational Geometry

Polygon Triangulation

Lecture 16: Voronoi Diagrams and Fortune s Algorithm

1. Meshes. D7013E Lecture 14

An Implementation of a Near-Linear Polygon Triangulation Algorithm for General Polygons

Triangulation by Ear Clipping

1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls

Lecture 3 February 9, 2010

How Do Computers Solve Geometric Problems? Sorelle Friedler, University of Maryland - College Park

Lecture 7: Computational Geometry

Line Arrangement. Chapter 6

CS S Lecture February 13, 2017

Geometric Streaming Algorithms with a Sorting Primitive (TR CS )

The following is a summary, hand-waving certain things which actually should be proven.

COMPUTING CONSTRAINED DELAUNAY

Vesa Halava Tero Harju. Walks on Borders of Polygons

Combinatorial Gems. Po-Shen Loh. June 2009

Computational Geometry

Cutting out polygons with a circular saw

Matching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.

Lecture 3 February 23, 2012

Stabbers of line segments in the plane

Notes in Computational Geometry Voronoi Diagrams

Crossing Families. Abstract

Computational Geometry Algorithmische Geometrie

Computing the Fréchet Distance Between Simple Polygons

Range Tree Applications in Computational Geometry

Pebble Sets in Convex Polygons

Rubber bands. Chapter Rubber band representation

Chapter 6. Planar Orientations. 6.1 Numberings of Digraphs

Computational Geometry. Lecture 17

The Art Gallery Problem

Computational Geometry [csci 3250]

Coverage and Search Algorithms. Chapter 10

Bicriteria approach to the optimal location of surveillance cameras *

CSE 546, Fall, 2016 Homework 1

Detecting intersections between convex polyhedra

G 6i try. On the Number of Minimal 1-Steiner Trees* Discrete Comput Geom 12:29-34 (1994)

Complexity of Octagonal and Rectangular Cartograms

arxiv: v1 [cs.cg] 8 Jan 2018

The Graphs of Triangulations of Polygons

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

Computational Geometry: Lecture 5

Edge Guards for Polyhedra in Three-Space

K-structure, Separating Chain, Gap Tree, and Layered DAG

Computational Geometry

6.854J / J Advanced Algorithms Fall 2008

implementing the breadth-first search algorithm implementing the depth-first search algorithm

AN OUTPUT-SENSITIVE ALGORITHM FOR COMPUTING VISIBILITY GRAPHS*

Notes and Answers to Homework Exam 1, Geometric Algorithms, 2017

Advanced Algorithm Homework 4 Results and Solutions

Solutions to Problem Set 1

Coloring Variations of the Art Gallery Problem

Chapter 8. Voronoi Diagrams. 8.1 Post Oce Problem

Discharging and reducible configurations

Decomposition of the figure-8 knot

Triangulation: basic graphics algorithms

(Refer Slide Time: 00:02:00)

Transcription:

EECS 396/496: Computational Geometry Fall 2017 Lecture 3: Art Gallery Problems and Polygon Triangulation Lecturer: Huck Bennett In this lecture, we study the problem of guarding an art gallery (specified by a simple polygon) using triangulation. 1 We break down the problem of how to guard a simple polygon into the following pieces: 1. How to triangulate a simple polygon. (a) How to break a simple polygon into monotone pieces. (b) How to triangulate a monotone polygon. 2. How to guard a triangulated, simple polygon. We present algorithms for the problems in Items 1a, 1b, and 2 separately. Combining them to get a full algorithm for guarding is simple. Item 1, the question of how to triangulate a polygon, is also interesting in its own right. 1 Art Gallery Problems In Lecture 0, we introduced the following problem. Suppose that you are put in charge of security at an art gallery. Your goal is to place cameras which put together can see the entire gallery, while placing as few cameras as possible. (The cameras can rotate 360 but can t move.) Of course, the number of cameras necessary and their placement depend on the shape of the gallery. If the gallery is a rectangle (or in fact any convex shape) a single camera suffices. On the other hand, it is not hard to design complicated galleries which require arbitrarily many cameras to guard. In this lecture, we study the problem of placing cameras to guard an art gallery which is specified as a simple polygon. This is an important case of the general class of problems called art gallery problems. A simple polygon P R 2 is one which is enclosed by a single polygonal chain that does not intersect itself. In particular, a simple polygon does not contain any holes. We treat cameras as points p P, and define the visibility region of p as the set of points q P such that the line segment pq is contained in P. We now formalize the (simple, polygonal) art gallery problem as follows. We are given as input a simple polygon with n vertices specified by a doubly-connected edge list (as defined in [dbcvko08, Chapter 2.2]). The goal is to find a set of points p 1,..., p m of minimal size such that the union of the visibility regions of the points p i covers all of P. A diagonal of a polygon is a line segment which lies in its interior and connects two of its vertices. A triangulation of a polygon is a maximal set of diagonals which partitions the polygon into interior-disjoint triangles. The requirement that the set of diagonals is maximal ensures that no triangle has a diagonal lying interior to an edge. (See Figure 1.) Every simple polygon has a triangulation (as we will show shortly), but generally such a triangulation is not unique. Sometimes it is useful to focus on triangulations which have nice properties such as having short diagonals, not having any sharp angles, or having low stabbing number (See [dbcvko08, Exercise 3.13]. However for the purposes of this lecture any triangulation will suffice. To see how triangulations are useful for guarding, note that because triangles are convex we can guard the entire gallery by placing a camera in each triangle. In fact, we can do even better and guard several triangles at once by placing cameras at vertices. Our main algorithm for guarding a gallery will be a simple scheme for placing cameras at the vertices of a triangulated polygon while using relatively few cameras. We first show that every simple polygon has a triangulation. 1 This lecture is based on [dbcvko08, Chapter 3]. 1

2 Lecture 3: Art Gallery Problems and Polygon Triangulation Figure 1: A simple, triangulated polygon together with its dual graph (left), and a 3-coloring of the vertices of the polygon (right). On the left, the simple polygon appears in black, its triangulation appears in gray, and the dual graph of its triangulation appears in red. On the right, the vertices of the polygon are colored white, gray, and black in such a way that no two adjacent vertices have the same color. Theorem 1.1. Every simple polygon P with n 3 vertices has a triangulation, and every triangulation of P consists of n 2 triangles. Proof. We argue by induction. For the base case, note that the claim clearly holds if P is itself a triangle. For the inductive case where n 4, the key is to find a diagonal in P. We do this as follows. Start with the leftmost vertex v of P, and look at its two neighbors, u and w. (If there are multiple leftmost vertices, let v be the bottom one.) If the line segment uw lies inside P, then it s a diagonal of P and we re done. Otherwise, consider the leftmost vertex v of P lying inside the triangle formed by u, v, and w. The line segment vv cannot intersect any edge of P since if it did one of the endpoints of the edge would be to the left of v. Therefore, vv is a diagonal of P. We have shown that a diagonal exists, and now need to prove that triangulation exists. Any diagonal splits P into two sub-polygons P 1 and P 2 which share the diagonal as an edge, and have m 1 and m 2 vertices, respectively. Both m 1 and m 2 are smaller than n, so by induction P 1 and P 2 can be triangulated. Taking the triangulations of P 1 and P 2 together with their shared diagonal gives a triangulation of P. Finally, we show that any triangulation partitions P into n 2 triangles. Consider an arbitrary diagonal in an arbitrary triangulation of P. This diagonal again partitions P into two sub-polygons P 1 and P 2 which share the diagonal as an edge, and have m 1 and m 2 vertices, respectively. Because m 1 and m 2 are smaller than n, we again have by induction that any triangulations of P 1 and P 2 partition them into m 1 2 and m 2 2 triangles, respectively. Every vertex of P occurs in exactly one of P 1 and P 2, except for the two vertices occurring in their shared diagonal, so n = m 1 + m 2 2. Therefore, the triangulation partitions P into (m 1 2) + (m 2 2) = n 2 triangles. We have shown that every polygon has a triangulation. In fact, our proof was constructive: we showed not only that a diagonal always exists in a simple polygon with more than four vertices, but how to find one. However, our algorithm needs to iterate through all of the polygon s vertices in order to find a diagonal (first to check whether uw lies in P, and then to find the leftmost vertex between u and w if not). This takes O(n)-time. Furthermore, it may be the case that P 1 is a triangle at each step, in which case we have to recurse on P 2 which has n 1 vertices. The overall time needed to find a triangulation using the implicit algorithm in our proof is therefore O(n 2 ). In Section 2 we show a faster but more complicated algorithm for triangulation. However, before presenting it we show how to use the added information given by a triangulation to guard a gallery.

Lecture 3: Art Gallery Problems and Polygon Triangulation 3 1.1 Guarding a Triangulated, Simple Polygon Our strategy for guarding a gallery will be to place cameras at vertices of P. The algorithm is as follows. Color the vertices of P black, white, and gray so that the vertices of each triangle are different colors (i.e., so that every triangle has a vertex of each color). There will then be either n/3 or n/3 vertices of each color. Pick a color appearing at n/3 vertices, and place a camera at each vertex of that color. Each triangle has a vertex of each color, and therefore the visibility regions of these cameras cover all of P. In our description of our coloring algorithm above, we assumed that every triangulated simple polygon has a 3-coloring, and that we could find it efficiently. We next show how to do this by looking at the dual graph G(T P ) of a triangulation T P of P. Let t(v) denote the triangle in T P corresponding to a node v in G(T P ). The dual graph of T P has a vertex for every triangle in T P, and an edge between every pair of vertices u and v whose corresponding triangles t(u) and t(v) share a diagonal in T P (see Figure 1). Removing any diagonal in T P splits P into two sub-polygons. Corresondingly, removing any edge in G(T P ) splits G(T P ) into two sub-graphs. In other words, G(T P ) is a tree. Our algorithm for 3-coloring the vertices of P is then as follows. Fix an arbitrary vertex v in G(T P ) as the root of G(T P ), and color the vertices of t(v) each with a different color (among black, gray, and white). Then, do a depth-first search of G(T P ). For every non-root vertex w encountered in the search, the triangle t(w) will share a diagonal with the triangle t(u), where u is the parent of w in G(T P ). The two vertices on the shared diagonal will already be colored. Color the third, uncolored vertex of t(w) with the remaining color. Because G(T P ) is a tree, there is a unique path from v to w. Therefore the only neighbor of w that will have been processed is its parent u, and therefore the third vertex of t(w) is always uncolored when the search first reaches w. We have shown that every simple polygon can be guarded using n/3 guards. Although this number of guards is clearly excessive sometimes (for example, when P is convex), Chvátal [Chv75] proved that sometimes it is necessary. Chvátal s example showing this is a comb-shaped gallery where each of the comb s teeth needs to be guarded by a separate camera. Overall, we have shown the following. Theorem 1.2 (Art Gallery Theorem, [Chv75]). Using n/3 cameras is always sufficient and sometimes necessary to guard a simple polygon with n vertices. Moreover, our proof of Theorem 1.1 was constructive, and showed how to find a triangulation in O(n 2 )- time. Once we had the coloring, we showed how to 3-color the vertices of P (and thus place cameras) in O(n)-time. So, overall we have an O(n 2 )-time algorithm for guarding a gallery. We next give a faster algorithm for triangulation, which in turn improves the overall runtime. 2 Faster Polygon Triangulation Our faster triangulation algorithm will work in two parts: breaking a simple polygon P into monotone pieces, and then triangulating each monotone piece. 2.1 Breaking a Polygon into Monotone Pieces A polygon P is called y-monotone if for every horizontal line l (i.e. for every line perpendicular to the y-axis) P l is connected. Note that y-monotonicity is a weaker property than convexity: every convex polygon is y-monotone, but not every y-monotone polygon is convex. See Figure 2. For points p, q, we define the ordering p < q if p y < q y or if p y = q y and p x > q x. If p < q then we say that p is below q, and if q < p then we say that p is above q. Consider a walk around the vertices of a polygon in either clockwise or counter-clockwise order. A vertex at which the direction of the walk goes from up to down or vice-versa is called a turn vertex. The key to partitioning a polygon P into monotone pieces will be to remove certain bad turn vertices by adding diagonals to P. Specifically, these bad vertices are ones where the interior of the polygon locally lies above

4 Lecture 3: Art Gallery Problems and Polygon Triangulation P 1 l P 2 P 3 l Figure 2: A non-convex, y-monotone polygon P 1 (left), a non-y-monotone polygon P 2 (center), and a non-ymonotone polygon with turn vertices shown in red and green (see Table 1 for an explanation of turn vertices and the color scheme), and non-turn vertices shown in black. Neighbors below Neighbors above < 180 interior angle Start vertex End vertex > 180 interior angle Split vertex Merge vertex Table 1: A comparison of the four types of turn vertices. The colors correspond to the scheme for turn vertices in Figure 2. Split vertices and merge vertices are the source of non-y-monotonicity in a polygon (see Lemma 2.1). it and whose neighbors lie below it, called split vertices, and ones where the interior of the polygon locally lies below it and whose neighbors lie above it, called merge vertices. We can classify split vertices and merge vertices together as those that have an interior angle of greater than 180. There are also harmless turn vertices called start vertices and end vertices that have interior angles of less than 180. See Figure 2. If we add a diagonal from a split vertex v to a vertex above it, then the diagonal splits P into two sub-polygons P 1 and P 2, with v appearing in both. However, v is not a split vertex (or merge vertex) in either P 1 or P 2 : the added diagonal goes up from v in both P 1 and P 2, and one neighbor of v in each of P 1 and P 2 still lies below v. Similarly, we can remove a merge vertex in P by adding a diagonal to a vertex below it. Split and merge vertices are clearly a source of local non-y-monotonicity. The next lemma shows that they are also the only sources of global non-y-monotonicity. Lemma 2.1. A polygon is y-monotone if and only if it has no split or merge vertices. Proof. Let P be a polygon. For the only if part, consider a horizontal line l slightly below a split vertex so that it cuts through both edges attached to the vertex. Similarly, consider a horizontal line slightly above a merge vertex so that it cuts through both edges attached to v. In either case, l P is not connected. We next show the if part by assuming that P is non-y-monotone, and proving that it has either a split or merge vertex. Since P is not monotone, there is a line l for which P l has (at least) two components. Moreover, we can pick such an l such that the left component is a line segment rather than a single point. Let p and q be the left and right endpoints of the leftmost segment in P l, and let r be the next leftmost intersection point of P and l. Refer to Figure 3. In the first case, by walking counter clockwise from q we encounter a split vertex between q and r. In the second case, by walking clockwise from q we encounter a merge vertex between r and r. Because P is simple one of the two cases in Figure 3 must hold. The algorithm for partitioning a simple polygon P with n vertices into monotone sub-polygons leverages Lemma 2.1. The basic idea is to use a line-sweep algorithm like we saw in Lecture 2. Again, we use a priority

Lecture 3: Art Gallery Problems and Polygon Triangulation 5 Figure 3: A non-y-monotone polygon must have either a split vertex (left) or a merge vertex (right). queue Q and a balanced binary search tree T. The event points, which are stored in Q, are the n vertices of P ; a point p has higher priority than a point q if p > q. (Actually, since we know all of the event points ahead of time, we can just sort them by priority at the beginning and don t need to use a priority queue.) I.e., our line sweep algorithm again works from top to bottom. The tree T stores the edges of P which intersect with the sweep line in order from left to right. The main idea is to attach new diagonals to split and merge vertices when we encounter them in the sweep. For split vertices, this is relatively straightforward: we can attach it to the lowest polygon vertex above the sweep line, or to the upper endpoint of one of the line segments adjacent to the split vertex on the sweep line (which we can determine from T ). For merge vertices the situation is more complicated, since we need to attach the merge vertex to a vertex below the sweep line (which we haven t processed yet). We omit the details of the algorithm which include substantial case analysis for handling each of the five types of polygon vertices (four types of turn vertices plus non-turn vertices), and appear in [dbcvko08, Chapter 3.2]. The proof of correctness for the algorithm primarily involves arguing that the introduced diagonals do not intersect the edges of P or each other. As in our plane sweep algorithm for computing line segment intersections, handling each event point requires performing a constant number of operations on Q and T, and therefore takes O(log n)-time. Overall, our algorithm therefore takes O(n log n)-time. This leads to the following theorem. Theorem 2.2. There exists an algorithm which partitions a simple polygon with n vertices into monotones pieces, and which runs in O(n log n)-time. 2.2 Triangulating a Monotone Polygon As the last piece of our algorithm, we show how to triangluate a monotone polygon P. We will process the vertices in P from top to bottom, where the leftmost of two points with the same y-coordinate is considered to be above the rightmost as in Section 2.1. (In fact, for simplicity in our description, we will assume that P is strictly y-monotone, i.e., that it does not have any vertices with the same y-coordinates.) The idea will be to greedily add diagonals between vertices in the left boundary chain and vertices in the right boundary chain of P. (The left and right boundary chains are defined as the sequence of vertices encountered when walking from the top to bottom vertex of P in counter clockwise order, and the sequence encountered when walking in clockwise order, respectively.) Our algorithm will use a stack S as its main data structure. To process a vertex v, we first add diagonals to as many of the vertices on top of S as possible. When we add a diagonal to such a vertex w from a lower vertex v, we remove w from S, which corresponds to removing a triangle from P. We then push v (and possibly its predecessor) onto S. Because we push vertices onto S as we encounter them, lower vertices of P appear higher in S. In particular, the top vertex in S is the most recently encountered vertex of P. After processing any given vertex, the vertices in S all lie on either the left or right boundary chain. Moreover, these vertices are all reflex vertices, meaning that their interior angle in P is greater than 180.

6 Lecture 3: Art Gallery Problems and Polygon Triangulation v i v i v j v j Figure 4: The state of the algorithm after processing a vertex v i that lies on the opposite chain from those in S (left), and after processing a vertex v j that lies on the same chain as those in S (right). The triangles removed from P appear shaded in gray. So, the part of P that lies above the last processed vertex and has not been removed has a funnel shape consisting of a chain of reflex vertices on one side, and part of a single edge of P on the other. Using this observation, we determine how to handle a newly encountered vertex. Consider a new vertex v i that lies on the opposite chain as the vertices in S. Then it is the endpoint of the edge in the funnel. We can then add diagonals between v i and all of the vertices in S except the last one (see Figure 4, left). Next, consider a new vertex v j that lies on the same chain as the vertices in S. In this case we may not be able to add diagonals to any new vertices. However, the vertices to which we can add diagonals still lie on top of S. Specifically, we add a diagonal between v j and a vertex w in S if the line segment wv j lies in P (see Figure 4, right). We can check this by determining whether w, the previously popped vertex, and v j form a right turn. We now present the algorithm more formally. Algorithm 1: TriangulateMonotonePolygon(P ) Input: A strictly y-monotone polygon P with n vertices, represented by a doubly-connected edge list. Output: A triangulation of P. Sort the vertices of P from top to bottom to obtain the sequence v 1 > > v n. Initialize a stack S, and push v 1 and then v 2 onto S. for i = 3 to n 1 do if v i and the top vertex of S lie on different chains then Pop all vertices from S. Add a diagonal from v i to all popped vertices except the last one. Push v i 1 and then v i onto S. else Pop a vertex from S. while The diagonal from v i to w lies in P, where w is the top vertex of S do Pop w from S. Add a diagonal from v i to w. end Push the last vertex popped back onto S, and then push v i onto S. end end Add diagonals from v n to all vertices in S except the first and last ones. We next analyze the time complexity of Algorithm 1. Theorem 2.3. Algorithm 1 triangulates a strictly y-monotone polygon P with n vertices in O(n)-time.

Lecture 3: Art Gallery Problems and Polygon Triangulation 7 Proof. Because P is represented in the input by a doubly-connected edge list, we can sort the vertices in P according to their y-coordinate in linear time by iterating through the vertices in the left and right boundary chains of P starting at the topmost vertex. Initializing S takes constant time. We next analyze the time required by the for loop. Although we may pop many vertices from S in a given iteration, the key observation is that we only push at most two vertices onto S at each iteration. Accounting for the two vertices initially pushed onto S and each iteration through the for loop we therefore push at most 2n 4 vertices onto S. This clearly also upper bounds the number of vertices popped from S, and handling each popped vertex takes constant time. Therefore, Algorithm 1 runs in O(n)-time. 3 Summary To review, let s look again at the pieces of our algorithm for guarding a simple polygon together with their runtimes: 1. Triangulating a simple polygon, described in Section 2. Runtime: O(n log n). (a) Breaking a simple polygon into monotone pieces, described in Section 2.1. Runtime: O(n log n). (b) Triangulating each monotone polygon, described in Section 2.2. Runtime: O(n). 2. Guarding a triangulated, simple polygon, described in Section 1.1. Runtime: O(n). Overall we get the following theorem. Theorem 3.1. For every simple polygon P with n vertices, there exists a set of n/3 camera placements which guard all of P. Furthermore, there exists an algorithm which computes such a set of placements and which runs in O(n log n)-time. The runtime bottleneck for our algorithm is in computing a triangulation in Step 1, and not in using the triangulation to place cameras in Step 2. Therefore a natural question is whether it s possible to triangulate a polygon more quickly. Chazelle [Cha91] showed that it is, and gave an O(n)-time algorithm for triangulating a simple polygon. (The algorithm is very complicated compared to the one presented in this lecture.) As a consequence, the runtime in Theorem 3.1 can be improved to O(n), which is optimal. References [Cha91] [Chv75] Bernard Chazelle. Triangulating a simple polygon in linear time. Discrete & Computational Geometry, 6:485 524, 1991. V. Chvátal. A combinatorial theorem in plane geometry. Journal of Combinatorial Theory, Series B, 18(1):39 41, 1975. [dbcvko08] Mark de Berg, Otfried Cheong, Marc J. van Kreveld, and Mark H. Overmars. Computational geometry: algorithms and applications, 3rd Edition. Springer, 2008.