Algorithm for Triangulating a Simple Polygon
Total Page:16
File Type:pdf, Size:1020Kb
On the Agenda Computational Geometry The Art Gallery Problem Polygon Triangulation Chapter 3 Polygons and Triangulation 13. 23. Art Gallery Problem Observations Given a simple polygon P, say The entire interior of a convex that two points p and q can see polygon is visible from any each other if the open segment pq R interior point. lies entirely within P. p q A point guards a region R ⊆ P if p convex sees all q∈R. Given a polygon P, what is the p non star-shaped minimal number of guards required A star-shaped polygon requires to guard P, and what are their only one guard located in its locations ? kernel . (actually this is the definition of a star-shape star-shaped polygon) 33. 43. Art Gallery Problem – Easy Upper Diagonals in Polygons Bound A diagonal of a polygon P is a line segment connecting two non-adjacent vertices, which lies entirely within P. Theorem: Any polygon with n>3 vertices n-2 guards suffice: has a diagonal, which may be found in Subdivide the polygon into n-2 O( n) time. triangles (triangulation) u Proof: Find the leftmost vertex v. Connect (we will show that this is the correct number of triangles) its two neighbors u and w. If this is not a diagonal there are other vertices inside v Place one guard in each triangle. the triangle uvw. Connect v to the vertex v’ v’ furthest from the (line containing the) w Theorem : Any simple planar polygon segment uw . with n vertices has a triangulation of size n-2. 53. 63. 1 O( n2) Polygon Triangulation Art Gallery Problem – Upper Theorem: Every simple polygon with Bound n vertices has a triangulation consisting of n-3 diagonals and n-2 Claim: n/3 guards are enough triangles. Color the vertices of the triangulated polygon with three colors, such that there is no edge Proof: By induction on n: Basis: A triangle between two vertices with the same color. (will (n=3) has a triangulation (itself) with no show that this doable) diagonals and one triangle. Pick a color which is least used. This color cannot appear more than n/3 times. Induction: for a n+1 vertex polygon, Place a guard on each vertex with this color. Each construct a diagonal dividing the polygon triangle has only one guarded vertex, but this guard covers all triangles incident on the vertex. into two polygons with n1 and n2 vertices such that n +n -2= n. Triangulate the two 1 2 ⇒ New upper bound: n/3 parts of the polygon. There are now n1-3+ n2-3+1= n-3 diagonals and n1-2+ n2-2= n-2 triangles. 73. 83. 3-Coloring Rembrandt Theorem: The vertices of the (triangulated) polygon may be 3-colored, so the colors of the vertices of Theorem: Every triangulated polygon has an ear each edge are different. Ear: a triangle containing two boundary edges). Proof: By induction on n: Basis: Trivial if n=3. Proof: Consider the dual to the triangulation. Every triangle -> vertex. Induction: Cut off an ear. Two neighboring triangles -> an edge. 3-color the n-1 vertex remainder. Since any diagonal disconnects the polygon, the dual Color the n’th vertex with the third color different from the two is a tree. on its supporting edge. The vertex degrees are bounded by 3. Ears correspond to leaves in the dual. 93. 103. O( n log n)-Time Polygon n/3 - Tight Bound Triangulation A simple (no holes) polygon P is called There exists a polygon monotone with respect to a direction ℓ if for ℓ any line ℓ ’ perpendicular to the intersection with n vertices, for which ℓ n/3 guards are necessary. of P with ’ is connected. A polygon is called monotone if there exists ℓ P any such direction . A polygon that is monotone with respect to both the x and y-axis is called x/y-monotone. ℓ ’ y-dir Question: How can we check in O( n) y-monotone but not x-monotone polygon time whether a polygon is y-monotone? 113. 123. 2 Classifying the vertices of Y-Monotone Triangulation Algorithm – cont. Polygons 1) Partition the polygon into y-monotone pieces. A start (resp., end ) vertex is one start whose interior angle is ≤π and its two neighboring vertices both lie below 2) Triangulate each y-monotone (resp., above) it. merge piece separately. A split (resp., merge ) vertex is one regular whose interior angle is ≥ π and its two split neighboring vertices both lie below (resp., above) it. All other vertices are regular . end 133. 143. Y-Monotone Polygons Monotone Partitioning start Theorem: A polygon without split Classify all vertices. and merge vertices is y-monotone. Sweep P (with a line) from top to bottom. merge Proof: Since there are only Maintain the edges intersected by the merge start/end/regular vertices, the sweep line in a sweep line status (SLS regular sorted by x coordinate). polygon must consist of two Maintain vertex events in an event queue y-monotone chains. split (EQ sorted by y coordinate). Alternatively, do a case analysis. Eliminate split/merge vertices by e helper (e) connecting them to other vertices, as end follow: split To partition a polygon to monotone pieces, eliminate For each edge e, define helper (e) as the split (merge) vertices by adding diagonals upward lowest vertex (seen so far) above the sweep line vertically visible to the right (downward) from the vertex. of the edge. Naturally, the diagonals must not intersect! helper (e) is initialized to the upper endpoint of e. 153. 163. Monotone Partitioning (cont.) Monotone Partitioning Algorithm ek helper (ej) A split vertex may be connected to the ej helper vertex of the edge immediately to Input: A counterclockwise ordered list of vertices of P. v its left (along the sweep line). i /* Notation: The edge e immediately follows the Question: Why this connection does not i ei intersect previously-made connections ? vertex v i CCK*/ Construct an EQ (events queue) on the vertices of P However, a merge vertex should be using y-coordinates. connected to a vertex which has not yet vi Initialize SLS ( sweep line status ) to be empty. been processed ! helper (e ) ek ej j While EQ is not empty: Clever idea: Every merge vertex is the vm Pop vertex v; helper of some edge, and will be handled Handle v. when this edge “terminates”. (No new events are generated during execution.) 173. Idea: No split/merge vertex remains unhandled! 183. 3 Monotone Partitioning Monotone Partitioning Handling an end vertex ( vi): v If helper (ei-1) is a merge 1 v8 Handling a start vertex (v i): v1 vertex, then connect v to i e1 v e9 v8 helper (e ) 3 e9 i-1 e7 Add ei to SLS e2 e e8 v 1 Else don’t connect vi e3 v2 3 e8 e helper (e ) := v v 7 v7 i i e2 9 Remove e from SLS i-1 v9 e v v5 3 2 v4 e4 e6 v7 e5 v5 v6 v4 e4 e6 e5 v6 193. 203. Monotone Partitioning Monotone Partitioning Handling a split vertex ( vi): Handling a merge vertex ( vi): Find in SLS the edge e If helper (e ) is a merge j v1 i-1 v1 directly to the left of vi vertex, then connect v i to e v8 v8 Connect v to helper (e ) 9 helper (ei-1) i j e9 e1 e1 v3 v3 e8 e Remove e from SLS e7 v helper (e ) := v v 7 i-1 e8 7 j i e2 9 e2 e v Find in SLS the edge e e v Insert ei into SLS 3 2 j 3 2 v directly to the left of vi 9 helper (ei) := v i v5 If helper (ej) is a merge v5 v4 e4 v7 v4 e4 e6 vertex, then connect v i to e5 e5 e6 helper (ej) v6 v6 helper (ej) := vi 213. 223. Triangulating a Y -monotone Polygon -warm - Monotone Partitioning ups Handling a regular vertex ( v): Recall – must consist of a left chain and i right chain If the polygon’s interior lies to the left of vi then: Find in SLS the edge e j Def: Convex vertex – interior angle ≤π . directly to the left of vi e Otherwise called reflex vertex. If helper (e ) is a merge 7 j Convex chain – consecutive part of the chain vertex, then connect v i to v 7 consisting of convex vertices. helper (ej) v2 helper (ej) := vi Else: Very easy to triangulate a chain of convex If helper (ei-1) is a merge vertices greedily connect them to a vertex on e6 vertex, then connect v i to the other side, or between themselves helper (ei-1) Remove ei-1 from SLS Insert e into SLS Preference to connect left chain to right, but i sometimes must connect within the same chain. helper (ei) := v i 233. 243. 4 Triangulating a Y -monotone Polygon Triangulating a Y -monotone Sweep the polygon from top to bottom. Greedily triangulate anything possible Polygon above the sweep line, and then forget about this region. (order irrelevant) When we process a vertex v, the Continue sweeping while one unhandled region above it always chain contains only one edge, has a simple structure: Two y-monotone (left and right) while the other edges are reflex. chains, each containing at least one When a “convex edge” appears in edge. If a chain consists of two or more edges, it is reflex , and the the concave chain (or a second other chain consists of a single edge edge appears in the other one), whose bottom endpoint has not been triangulate as much as possible handled yet.