Lecture on Triangulation, Trapezoidalization, and Polygon Partitioning ====================================================================== Goals ----- See how computational geometers work: - improvement of complexity - simplification of algorithm Start introducing algorithms and data structures Prove correctness Look at some details of the algorithm not just intution Point out why the proofs we'll talk about next time are relevant Overview -------- Trival Algorithm (special case) Naive Algorithm Intuitive Algorithm Easy Algorithm (special case) General Algorithm We will not discuss O(n) algorithm by Chazelle Bernard Chazelle. Triangulating a simple polygon in linear time. Discrete and Computational Geometry, 6(5):485-524, 1991. Warm-up ------ What is the sum of internal angles of a plygon of n vertices? (n-2)Pi PROOF: There are n-2 triagles in a triangulation of a polygon. Each contributes Pi to the internal angles. Every vertex of each triangle is also a vertex of the polygon, therfore every angle of the triangle is part of an internal angle of the polygon. what we need to prove: - triangulation always exists - size of triangulation DEF: a *polygon* is a closed, connected non-self-intersecting boundary in the plane (polyhedron in 3D, polychronon in 4D, polytope in nD) DEF: the *diagonal* of a polygon P is a line segment between two of its non-adjacent vertices a and b that are visibile to one another. For an interior diagonal, the line segment has to be inside the polygon; an exterior diagonal is outside the polygon. DEF: a *triangulation* is a partitioning of a polygon into triangles using interior diagionals Counting -------- Every triangulation of a polygon P of n vertices, uses n-3 diagonals, and consists of n-2 triangles. Trivial Algorithm (Still warm-up) ----------------- Convex polygon: pick a vertex and connect to all others. O(n) DEF: a polygon is convex is the line connecting any two points in its interior is itself entirely inside the polygon Naive Algorithm --------------- - generate all (n choose 2) edges O(n^2) - insert if edge does not intersect with any other edge already there - complexity O(n^3) Intuitive Algorithm: Ear Clipping ------------------------------ DEF Ear: three consecutive vertices a,b,c form an *ear* of a polygon if ac is a diagonal (interior) triangluate(P) if (n>3) then for each potential ear diagonal (i,i+2) do if diagonal (i,i+2) then add diagonal remove ear at i,i+2 from P triangulate(P) what we need to program: - diagonal check . in cone . nonintersect - remove ear complexity? O(n^3) -> O(n^2) by saving intersection computations alternative implementation: triangulate(P) compute ear tip status for all vertices in O(n^2) while n>3 locate an ear tip at v_i output diagonal v_{i-1}v_{i+1} delete v_i update ear tip status updating ear tip status has to be show to only affect neighbors, left as an exercise! DEF: binomial coefficient (n choose k) = n! / ((n-k)! k!) what we need to prove: - a diagonal always exists - an ear always exists Does a diagonal always exist? ----------------------------- (Meisters theorem) Every simple polygon with with |P|>3 contains a diagonal. Proof: Consider sweepline algorithm. Or: Consider two cases for a vertex v and it's neighbors: it either sees a vertex w - and then vw is a diagonal, or it does not, and then the neighbors of v can be connected to form a diagonal. Does an ear always exist? ------------------------- (Meisters' two ear theorem) Consider the dual of the triangulation (tree). Ears correspond to the leaves of the tree. A tree of two or more nodes has at least two leaves. Monotone Decomposition ---------------------- Concept introduced by Lee and Preparata in 1977 DEF: strictly monotone wrt/ line (polygonal chain): intersection a single point DEF: monotone wrt/ line (polygonal chain): intersection a single connected component DEF: (striclty) monotone wrt/ line (polygon): polygon can be split into two polygonal chains that are (strictly) monotone wrt/ line ASSUMPTION: line of monotonicity is the vertical Monotonicity is interesting because is allows linear time algorithms for many problems that are difficult with general polygons. Reason: vertices are sorted. ASSUMPTION: strictly monotonic Is the dual of the triangulation of a strictly monotone polygon always a path? Is every diagonal between the two monotone chains? Triangulation of a strictly monotone polygon -------------------------------------------- Idea: sort vertices O(n), cut triangles in greed fashion top->bottom O(n). Algorithm: for each vertex v, connect to all visible vertices above it, cut off triangle, repeat for next lowest vertex DEF: a polygonal chain is a *reflex chain* if all vertices have an internal angle >= Pi Case1: v is on chain opposite to reflex chain -> cut triangle Case2: v is at bottom of reflex chain a) vertex above v is striclty convex -> cut triangle b) vertex above v is reflex or flat -> add v to chain; advance Are these the only cases? LEMMA: At the start of each iteration the following holds: 1) all vertices above v are in one chain and 2) the chain is reflex Proof by contradiction. Why is this interesting? Most polygons are not monotone!!! But: there is an O(n log n) algorithm to decompose a simple polygon into monotone pieces (see textbook), which each can be triangulated in O(n). Now we can triangulate any polygon in O(n log n) time. Trapezoidal Decomposition of a Polygon -------------------------------------- DEF: horizontal/vertical trapezoidalization ASSUMPTION: no two vertices have the same x coordinate ASSUMPTION made very often: general position of vertices DEF: *trapezoid* is a quadrilateral with two parallel edges Draw example. DEF: *supporting vertex* is the vertex from which the ray is emanated We are allowed to add vertices!!! Line Sweep Algorithm Idea: - sweep line - keep data structure with events - Nievergelt and Preparata, 1982 Line Sweep: - sort all points along y in (n log n) - now we can advance the line in steps to "events" At each event: - we need to cast the appropriate rays in both directions - to do that we need to know adjacent edges to v on sweep line - assume we have an ordered list of edges currently intersecting the sweep line (we'll discuss this later) - now we can . find the two edges adjacent to v in O(n log n) . update the list in O(1) (how is next) Updates of edge list intersecting sweep line: - crossing vertex: (...,a,c,b,...) => (...,a,d,b,...) - leaving at vertex (...,a,c,d,b,...) => (...,a,b,...) - arriving at vertex (...,a,b,...) => (...,a,c,d,b,...) - each update O(1) Runtime: sorting: O(n log n) n events each O(log n) => O(n log n) overall: O(n log n) Connection to monotone polygons: trapezoidal decomposition can be used to "monotonize" a polygon (proof?) Trapezoidal Decomposition of a Set of Line Segments --------------------------------------------------- Counting for n line segments: at most k = (n choose 2) intersections of line segments at most v = 2n+k vertices Counting for trapezoidal decomposition of n line segments: at most 6n+4 = 4 + 2n + 2(2n) vertices at most 3n+1 trapezoids consider left supporting vertex - left endpoints - right endpoints - rectangle Outlook: -------- Delaunay triangulation - dual of Voronoi diagram - many more nice properties . maximizes minimum angle in each triangle . minimizes maximum radius of circumcircle and enclosing circle . minimizes sum of inscribed radii . many more - O(n log n)