220 likes | 444 Views
UMass Lowell Computer Science 91.504 Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2001. Lecture 2 Chapter 2: Polygon Partitioning Chapter 3: 2D Convex Hulls Monday, 2/12/01. Chapter 2. Polygon Partitioning useful for triangulations and many other uses!.
E N D
UMass Lowell Computer Science 91.504Advanced AlgorithmsComputational GeometryProf. Karen DanielsSpring, 2001 Lecture 2 Chapter 2: Polygon Partitioning Chapter 3: 2D Convex Hulls Monday, 2/12/01
Chapter 2 Polygon Partitioning useful for triangulations and many other uses!
Monotone Partitioning • A chain is monotone with respect to a line L if every line orthogonal to L intersects the chain in at most 1 point • P is monotone with respect to a line L if boundary of P can be split into 2 polygonal chains A and B such that each chain is monotone with respect to L • Monotonicity implies sorted order with respect to L • Monotone polygon can be (greedily) triangulated in O(n) time
Trapezoidalization • Partition into trapezoids • Horizontal line through each vertex • Diagonal with each “supporting” vertex yields monotone partition • To trapezoidalize, vertically sweep a lineL • presort vertices by y (O(nlogn) time) • maintain sorted list of edges intersecting L • lg n lookup/insert/delete time (e.g. ht-balanced tree) • for each vertex • find edge left and right along sweep line Algorithm: POLYGON TRIANGULATION: MONOTONE PARTITION Sort vertices by y coordinate Perform plane sweep to construct trapezoidalization Partition into monotone polygons by connecting from interior cusps Triangulation each monotone polygon in O(n) time O(n lg n)
Partition into Monotone Mountains • One monotone chain is a single segment • Every strictly convex vertex is an ear tip (except maybe base endpoints) Algorithm: TRIANGULATION of MONOTONE MOUNTAIN Identify base edge Initialize internal angles at each nonbase vertex Link nonbase strictly convex vertices into a list while list nonempty do For convex vertex b, remove triangle abc Output diagonal ac Update angles and list O(n)
Linear-Time Triangulation Year Complexity Authors
Linear-Time Triangulation • Chazelle’s Algorithm (High-Level Sketch) • Computes visibility map • horizontal chords left and right from each vertex • Algorithm is like MergeSort (divide-and-conquer) • Partition polygon of n vertices into n/2 vertex chains • Merge visibility maps of subchains to get one for chain • Improve this by dividing process into 2 phases: 1) Coarse approximations of visibility maps for linear-time merge 2) Refine coarse map into detailed map in linear time
Seidel’s Randomized Triangulation • Simple, practical algorithm • Randomized: Coin-flip for some decisions • Build trapezoidalization quickly • O(log n) expected cost for locating point in query structure • Coin-flip to decide which segment to add next Trapezoidalize -> Monotone Mountain -> Triangulate
Convex Partitioning • Competing Goals: • minimize number of convex pieces • minimize partitioning time • To add points or not add points? Theorem (Chazelle): Let F be the fewest number of convex pieces into which a polygon may be partitioned. For a polygon of r reflex vertices:
Chapter 3 2D Convex Hulls
nonconvex polygon convex hull of a point set Convexity & Convex Hulls • A convex combination of points x1, ..., xk is a sum of the form a1x1+...+ akxk where • Convex hull of a set of points is the set of all convex combinations of points in the set.
Algorithm: INTERIOR POINTS for each i do for each j = i do for each k = j = i do for each L = k = j = i do if pL in triangle(pi, pj, pk) then pL is nonextreme Algorithm: EXTREME EDGES for each i do for each j = i do for each k = j = i do if pk is not left or on (pi, pj) then (pi , pj) is not extreme O(n3) Naive Algorithms for Extreme Points O(n4)
q Algorithm: GIFT WRAPPING i0 index of the lowest point i i0 repeat for each j = i Compute counterclockwise angle q from previous hull edge k index of point with smallest q Output (pi , pk) as a hull edge i k until i = i0 O(n2) Gift Wrapping • Use one extreme edge as an anchor for finding the next
a b Algorithm: QUICK HULL function QuickHull(a,b,S) if S = 0 return() else c index of point with max distance from ab A points strictly right of (a,c) B points strictly right of (c,b) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B) O(n2) QuickHull • Concentrate on points close to hull boundary • Named for similarity to Quicksort
Algorithm: GRAHAM SCAN, Version B Find rightmost lowest point; label it p0. Sort all other points angularly about p0. In case of tie, delete point(s) closer to p0. Stack S (p1, p0) = (pt, pt-1); t indexes top i 2 while i < n do if pi is strictly left of pt-1pt then Push(pi, S) and set i i +1 else Pop(S) q O(nlgn) Graham’s Algorithm • Points sorted angularly provide “star-shaped” starting point • Prevent “dents” as you go via convexity testing
Lower Bound of O(nlgn) • Worst-case time to find convex hull of n points in algebraic decision tree model is in W(nlgn) • Proof uses sorting reduction: • Given unsorted list of n numbers: (x1,x2 ,…, xn) • Form unsorted set of points: (xi, xi2) for each xi • Convex hull of points produces sorted list! • Parabola: every point is on convex hull • Reduction is O(n) (which is o(nlgn)) • Finding convex hull of n points is therefore at least as hard as sorting n points, so worst-case time is in W(nlgn) Parabola for sorting 2,1,3
Incremental Algorithm • Add points, one at a time • update hull for each new point • Key step becomes adding a single point to an existing hull. • Idea is extended to 3D in Chapter 4. Algorithm: INCREMENTAL ALGORITHM Let H2 ConvexHull{p0 , p1 , p2 } for k 3 to n - 1 do Hk ConvexHull{ Hk-1 U pk } O(n2) can be improved to O(nlgn)
Divide-and-Conquer • Divide-and-Conquer in a geometric setting • O(n) merge step is the challenge • Find upper and lower tangents • Lower tangent: find rightmost pt of A & leftmost pt of B; then “walk it downwards” • Idea is extended to 3D in Chapter 4. B A Algorithm: DIVIDE-and-CONQUER Sort points by x coordinate Divide points into 2 sets A and B: A contains left n/2 points B contains right n/2 points Compute ConvexHull(A) and ConvexHull(B) recursively Merge ConvexHull(A) and ConvexHull(B) O(nlgn)
Homework HW# Assigned DueContent • Fri, 2/9 Wed, 2/14 Chapter 1 (O’Rourke) problems 1 & 2 Extra credit may be turned in any time during week of 2/12 • Mon, 2/12 Wed, 2/21 Chapters 2,3 (O’Rourke) problems 1 & 2 Extra credit may be turned in any time during week of 2/21
Machine Accounts • Each student has an account on my machine: minkowski.cs.uml.edu • Username is the same as your username on CS • Password is your initials followed by the last 5 digits on the bottom right hand corner of the back of your student id card (1 exception) • To remotely log in, use a secure shell (e.g. ssh) • To transfer files, use a secure FTP (e.g. sftpc) • Saturn has an sftpc client • Code to use with assignments will be there.
Preparing for Homework 2 • Graham Scan 2D Convex Hull Code • Background on research problem that motivates problem 2