Polygon Triangulation

Similar documents
Polygon Partitioning. Lecture03

Polygon Triangulation. (slides partially by Daniel Vlasic )

Computational Geometry

CS6100: Topics in Design and Analysis of Algorithms

Computational Geometry [csci 3250]

Polygon Triangulation. (slides partially by Daniel Vlasic )

CS 373: Combinatorial Algorithms, Fall Name: Net ID: Alias: U 3 / 4 1

Polygon Triangulation

[Me] Meisters, G. H., Polygons have ears, American Mathematical Monthly, June/July 1975, pp

Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Lecture 3: Art Gallery Problems and Polygon Triangulation

Polygon decomposition. Motivation: Art gallery problem

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

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

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

AMS 345/CSE 355 Computational Geometry

CSE 546, Fall, 2016 Homework 1

Geometric Streaming Algorithms with a Sorting Primitive (TR CS )

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

Polygon Triangulation

CMSC 754 Computational Geometry 1

Lecture 4: Trees and Art Galleries

J Linear Programming Algorithms

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

MISCELLANEOUS SHAPES

Ma/CS 6b Class 11: Kuratowski and Coloring

The SUMO Speaker Series for Undergraduates. The Art Gallery Problem

9 Bounds for the Knapsack Problem (March 6)

The Art Gallery Problem

Discrete Mathematics I So Practice Sheet Solutions 1

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

CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk

Computational geometry

Art Gallery, Triangulation, and Voronoi Regions

Rubber bands. Chapter Rubber band representation

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College

AN OUTPUT-SENSITIVE ALGORITHM FOR COMPUTING VISIBILITY GRAPHS*

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College

Triangulation by Ear Clipping

Graduate Algorithms CS F-19 Computational Geometry

of Nebraska - Lincoln. Follow this and additional works at:

The convex hull of a set Q of points is the smallest convex polygon P for which each point in Q is either on the boundary of P or in its interior.

Accepting that the simple base case of a sp graph is that of Figure 3.1.a we can recursively define our term:

Advanced Algorithms Computational Geometry Prof. Karen Daniels. Spring, 2010

Planar Graphs. 1 Graphs and maps. 1.1 Planarity and duality

Computational Geometry

Projects & Polygon Triangulation

Combinatorial Gems. Po-Shen Loh. June 2009

My Favorite Problems, 4 Harold B. Reiter University of North Carolina Charlotte

Computational Geometry Lecture Duality of Points and Lines

CS4733 Class Notes. 1 2-D Robot Motion Planning Algorithm Using Grown Obstacles

Convex Hull Algorithms

On the Minimum Number of Convex Quadrilaterals in Point Sets of Given Numbers of Points

Triangulation and Convex Hull. 8th November 2018

Week 7 Convex Hulls in 3D

Geometric Algorithms. 1. Objects

2009 HMMT Team Round. Writing proofs. Misha Lavrov. ARML Practice 3/2/2014

Computational Geometry. Algorithm Design (10) Computational Geometry. Convex Hull. Areas in Computational Geometry

Lecture 18 Representation and description I. 2. Boundary descriptors

Tangencies between disjoint regions in the plane

Lecture 14: Computational Geometry Steven Skiena. skiena

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

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

A THREE AND FIVE COLOR THEOREM

CSE 5311 Notes 13: Computational Geometry

Week 2 Polygon Triangulation

Computational Geometry: Lecture 5

Last time. Today: Convex Hull Brute Force Inside(q,abc) Intersect(ab,cd) Orient(a,b,c).

Visibility Graph. How does a Mobile Robot get from A to B?

Lecture 11 Combinatorial Planning: In the Plane

Chapter 8. Voronoi Diagrams. 8.1 Post Oce Problem

The Art Gallery Problem

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

Computational Geometry [csci 3250]

An Overview of Triangulation Algorithms for Simple Polygons

Geometry. Zachary Friggstad. Programming Club Meeting

28 Adversary Arguments

Computational Geometry 2D Convex Hulls. Joseph S. B. Mitchell Stony Brook University

Pebble Sets in Convex Polygons

Elementary Planar Geometry

! Linear programming"! Duality "! Smallest enclosing disk"

Cross products. p 2 p. p p1 p2. p 1. Line segments The convex combination of two distinct points p1 ( x1, such that for some real number with 0 1,

Line Arrangements. Applications

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

Polygons. An investigation by Laura Escobar. Math Explorer s Club

Henneberg construction

Line Arrangement. Chapter 6

2 Geometry Solutions

Lecture 13 Geometry and Computational Geometry

Steven Skiena. skiena

DIHEDRAL GROUPS KEITH CONRAD

Computational Geometry

Computational Geometry

7.1 Interior and Exterior Angles

2D Geometry. Pierre Alliez Inria Sophia Antipolis

DIHEDRAL GROUPS KEITH CONRAD

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

Week 3 Polygon Triangulation

Flavor of Computational Geometry. Convex Hull in 2D. Shireen Y. Elhabian Aly A. Farag University of Louisville

Transcription:

If triangles had a god, they would give him three sides. Charles Louis de Secondat Montesquie (1721) Down with Euclid! Death to triangles! Jean Dieudonné (1959) P Polygon Triangulation P.1 Introduction Recall from last time that a polygon is a region of the plane bounded by a cycle of straight edges joined end to end. Given a polygon, we want to decompose it into triangles by adding diagonals: new line segments between the vertices that don t cross the boundary of the polygon. Because we want to keep the number of triangles small, we don t allow the diagonals to cross. We call this decomposition a triangulation of the polygon. Most polygons can have more than one triangulation; we don t care which one we compute. Two triangulations of the same polygon. Before we go any further, I encourage you to play around with some examples. Draw a few polygons (making sure that the edges are straight and don t cross) and try to break them up into triangles. P.2 Existence and Complexity If you play around with a few examples, you quickly discover that every triangulation of an n-sided has n 2 triangles. You might even try to prove this observation by induction. The base case n = 3 is trivial: there is only one triangulation of a triangle, and it obviously has only one triangle! To prove the general case, let P be a polygon with n edges. Draw a diagonal between two vertices. This splits P into two smaller polygons. One of these polygons has k edges of P plus the diagonal, for some integer k between 2 and n 2, for a total of k + 1 edges. So by the induction hypothesis, this polygon can be broken into k 1 triangles. The other polygon has n k + 1 edges, and so by the induction hypothesis, it can be broken into n k 1 tirangles. Putting the two pieces back together, we have a total of (k 1) + (n k 1) = n 2 triangles. Breaking a polygon into two smaller polygons with a diagonal. 1

This is a fine induction proof, which any of you could have discovered on your own (right?), except for one small problem. How do we know that every polygon has a diagonal? This seems patently obvious, but it s surprisingly hard to prove, and in fact many incorrect proofs were actually published as late as 1975. The following proof is due to Meisters in 1975. Lemma 1. Every polygon with more than three vertices has a diagonal. Proof: Let P be a polygon with more than three vertices. Every vertex of a P is either convex or concave, depending on whether it points into or out of P, respectively. Let q be a convex vertex, and let p and r be the vertices on either side of q. For example, let q be the leftmost vertex. (If there is more than one leftmost vertex, let q be the the lowest one.) If pr is a diagonal, we re done; in this case, we say that the triangle pqr is an ear. If pr is not a diagonal, then pqr must contain another vertex of the polygon. Out of all the vertices inside pqr, let s be the vertex furthest away from the line pr. In other words, if we take a line parallel to pr through q, and translate it towards pr, then then s is the first vertex that the line hits. Then the line segment qs is a diagonal. r q p r p s q The leftmost vertex q is the tip of an ear, so pr is a diagonal. The rightmost vertex q is not, since p q r contains three other vertices. In this case, q s is a diagonal. P.3 Existence and Complexity Meister s existence proof immediately gives us an algorithm to compute a diagonal in linear time. The input to our algorithm is just an array of vertices in counterclockwise order around the polygon. First, we can find the (lowest) leftmost vertex q in O(n) time by comparing the x-coordinates of the vertices (using y-coordinates to break ties). Next, we can determine in O(n) time whether the triangle pqr contains any of the other n 3 vertices. Specifically, we can check whether one point lies inside a triangle by performing three counterclockwise tests. Finally, if the triangle is not empty, we can find the vertex s in O(n) time by comparing the areas of every triangle pqs; we can compute this area using the counterclockwise determinant. Here s the algorithm in excruciating detail. We need three support subroutines to compute the area of a polygon, to determine if three poitns are in counterclockwise order, and to determine if a point is inside a triangle. Return twice the signed area of P[i]P[ j]p[k] AREA(i, j, k): return (P[k].y P[i]. y)(p[ j].x P[i].x) (P[k].x P[i].x)(P[ j]. y P[i].y) Are P[i], P[ j], P[k] in counterclockwise order? CCW(i, j, k): return AREA(i, j, k) > 0 Is P[i] inside P[p]P[q]P[r]? INSIDE(i, p, q, r): return CCW(i, p, q) and CCW(i, q, r) and CCW(i, r, p) 2

FINDDIAGONAL(P[1.. n]): q 1 for i 2 to n if P[i].x < P[q].x q i p q 1 mod n r q + 1 mod n ear TRUE s p for i 1 to n if i p and i q and i r and INSIDE(i, p, q, r) ear FALSE if AREA(i, r, p) > AREA(s, r, p) s i if ear = TRUE return (p, r) else return (q, s) Once we have a diagonal, we can recursively triangulate the two pieces. The worst-case running time of this algorithm satisfies almost the same recurrence as quicksort: T(n) max 2 k n 2 So we can now triangulate any polygon in O(n 2 ) time. T(k + 1) + T(n k + 1) + O(n). P.4 Faster Special Cases For certain special cases of polygons, we can do much better than O(n 2 ) time. For example, we can easily triangulate any convex polygon by connecting any vertex to every other vertex. Since we re given the counterclockwise order of the vertices as input, this takes only O(n) time. Triangulating a convex polygon is easy. Another easy special case is monotone mountains. A polygon is monotone if any vertical line intersects the boundary in at most two points. A monotone polygon is a mountain if it contains an edge from the rightmost vertex to the leftmost vertex. Every monotone polygon consists of two chains of edges going left to right between the two extreme vertices; for mountains, one of these chains is a single edge. A monotone mountain and a monotone non-mountain. 3

Triangulating a monotone mounting is extremely easy, since every convex vertex is the tip of an ear, except possibly for the vertices on the far left and far right. Thus, all we have to do is scan through the intermediate vertices, and when we find a convex vertex, cut off the ear. The simplest method for doing this is probably the three-penny algorithm used in the Graham s scan convex hull algorithm instead of filling in the outside of a polygon with triangles, we re filling in the inside, both otherwise it s the same process. This takes O(n) time. Triangulating a monotone mountain. (Some of the triangles are very thin.) We can also triangulate general monotone polygons in linear time, but the process is more complicated. A good way to visuialize the algorithm is to think of the polygon as a complicated room. Two people named Tom and Bob are walking along the top and bottom walls, both starting at the left end and going to the right. At all times, they have a rubber band stretched between them that can never leave the room. T B A rubber band stretched between a vertex on the top and a vertex on the bottom of a monotone polygon. Now we loop through all the vertices of the polygon in order from left to right. Whenever we see a new bottom vertex, Bob moves onto it, and whenever we see a new bottom vertex Tom moves onto it. After either person moves, we cut the polygon along the rubber band. (In fact, this will only cut the polygon along a single diagonal at any step.) When we re done, the polygon is decomposed into triangles and boomerangs nonconvex polygons consisting of two straight edges and a concave chain. A boomerang can only be triangulated in one way, by joining the apex to every vertex in the concave chain. 4

Triangulating a monotone polygon by walking a rubber band from left to right. I don t want to go into too many implementation details, but a few observations shoudl convince you that this algorithm can be implemented to run in O(n) time. Notice that at all times, the rubber band forms a concave chain. The leftmost edge in the rubber band joins a top vertex to a bottom vertex. If the rubber band has any other vertices, either they are all on top or all on bottom. If all the other vertices are on top, there are just three ways the rubber band can change: 1. The bottom vertex changes, the rubber band straighens out, and we get a new boomerang. 2. The top vertex changes and the rubber band gets a new concave vertex. 3. The top vertex changes, the rubber band loses some vertices, and we get a new boomerang. Deciding between the first case and the other two requires a simple comparison between x-coordinates. Deciding between the last two requires a counterclockwise test. c Copyright 2009 Jeff Erickson. Released under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License (http://creativecommons.org/licenses/by-nc-sa/3.0/). Free distribution is strongly encouraged; commercial distribution is expressly forbidden. See http://www.cs.uiuc.edu/~jeffe/teaching/algorithms/ for the most recent revision. 5