Upload
gray-gould
View
34
Download
0
Tags:
Embed Size (px)
DESCRIPTION
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!. - PowerPoint PPT Presentation
Citation preview
UMass Lowell Computer Science 91.504 Advanced Algorithms
Computational Geometry Prof. Karen Daniels
Spring, 2001
UMass Lowell Computer Science 91.504 Advanced Algorithms
Computational Geometry Prof. Karen Daniels
Spring, 2001
Lecture 2Lecture 2
Chapter 2: Polygon PartitioningChapter 2: Polygon Partitioning
Chapter 3: 2D Convex HullsChapter 3: 2D Convex HullsMonday, 2/12/01Monday, 2/12/01
Chapter 2Chapter 2
Polygon PartitioningPolygon Partitioninguseful for triangulations useful for triangulations
and many other uses!and many other uses!
Monotone PartitioningMonotone Partitioning
A A chainchain is is monotonemonotone with respect to a with respect to a line L if every line orthogonal to L line L if every line orthogonal to L intersects the chain in at most 1 pointintersects the chain in at most 1 point
PP is monotone with respect to a line L if is monotone with respect to a line L if boundary of P can be split into 2 boundary of P can be split into 2 polygonal chains A and B such that each polygonal chains A and B such that each chain is monotone with respect to Lchain is monotone with respect to L
Monotonicity implies sorted order with Monotonicity implies sorted order with respect to Lrespect to L
Monotone polygon can be (greedily) Monotone polygon can be (greedily) triangulated in O(n) time triangulated in O(n) time
TrapezoidalizationTrapezoidalization
Partition into trapezoids Partition into trapezoids Horizontal line through each vertexHorizontal line through each vertex Diagonal with each “supporting” vertex Diagonal with each “supporting” vertex
yields monotone partitionyields monotone partition To trapezoidalize, To trapezoidalize, vertically sweep vertically sweep a linea line LL
presort vertices by presort vertices by yy (O(nlogn) time) (O(nlogn) time) maintain sorted list of edges intersecting Lmaintain sorted list of edges intersecting L
lg n lookup/insert/delete time (e.g. ht-balanced lg n lookup/insert/delete time (e.g. ht-balanced tree)tree)
for each vertexfor each vertex find edge left and right along sweep linefind edge left and right along sweep line
AlgorithmAlgorithm: POLYGON TRIANGULATION: MONOTONE PARTITION: POLYGON TRIANGULATION: MONOTONE PARTITIONSort vertices by y coordinateSort vertices by y coordinatePerform plane sweep to construct trapezoidalizationPerform plane sweep to construct trapezoidalizationPartition into monotone polygons by connecting from interior cuspsPartition into monotone polygons by connecting from interior cuspsTriangulation each monotone polygon in O(n) timeTriangulation each monotone polygon in O(n) time O(n lg n)O(n lg n)
Partition into Monotone MountainsPartition into Monotone Mountains
One monotone chain is a single One monotone chain is a single segmentsegment
Every strictly convex vertex is Every strictly convex vertex is an ear tip an ear tip (except maybe base (except maybe base endpoints)endpoints)
AlgorithmAlgorithm: TRIANGULATION of MONOTONE MOUNTAIN: TRIANGULATION of MONOTONE MOUNTAINIdentify base edgeIdentify base edgeInitialize internal angles at each nonbase vertexInitialize internal angles at each nonbase vertexLink nonbase strictly convex vertices into a listLink nonbase strictly convex vertices into a listwhile list nonempty dowhile list nonempty do
For convex vertex b, remove triangle abcFor convex vertex b, remove triangle abcOutput diagonal acOutput diagonal acUpdate angles and listUpdate angles and list O(n)O(n)
Linear-Time TriangulationLinear-Time Triangulation
1911 O(n2) Lennes1978 O(n log n) Garey et al.1983 O(n log r), r reflex Hertel & Melhorn1984 O(n log s), s sinuosity Chazelle & Incerpi1986 O(n log log n) Tarjan & Van Wyk1988 O(n + nt0), t0 int. triangles Toussaint1989 O(n log* n), randomized Clarkson, Tarjan & Van Wyk1990 O(n log* n) bounded integer coordinates Kirkpatrick, Klawe, Tarjan1990 O(n) Chazelle1991 O(n log*n), randomized Seidel
YearYear ComplexityComplexity AuthorsAuthors
Linear-Time TriangulationLinear-Time Triangulation
Chazelle’s Algorithm (High-Level Sketch)Chazelle’s Algorithm (High-Level Sketch) Computes visibility mapComputes visibility map
horizontal chords left and right from each vertexhorizontal chords left and right from each vertex
Algorithm is like MergeSort (divide-and-conquer)Algorithm is like MergeSort (divide-and-conquer) Partition polygon of n vertices into n/2 vertex chainsPartition polygon of n vertices into n/2 vertex chains Merge visibility maps of subchains to get one for chainMerge visibility maps of subchains to get one for chain
Improve this by dividing process into 2 phases:Improve this by dividing process into 2 phases:1) Coarse approximations of visibility maps for linear-time 1) Coarse approximations of visibility maps for linear-time
mergemerge
2) Refine coarse map into detailed map in linear time2) Refine coarse map into detailed map in linear time
Seidel’s Randomized TriangulationSeidel’s Randomized Triangulation
Simple, practical algorithmSimple, practical algorithm Randomized: Coin-flip for some decisionsRandomized: Coin-flip for some decisions Build trapezoidalization quicklyBuild trapezoidalization quickly
O(log n) expected cost for locating point in query O(log n) expected cost for locating point in query structurestructure
Coin-flip to decide which segment to add nextCoin-flip to decide which segment to add next
Trapezoidalize -> Monotone Mountain -> Triangulate
Convex PartitioningConvex Partitioning
Competing Goals:Competing Goals: minimize number of convex piecesminimize number of convex pieces minimize partitioning timeminimize partitioning time
To add points or not add points?To add points or not add points?
Theorem (Chazelle): Let be the fewest number of convex pieces into which a polygon may be partitioned. For a polygon of r reflex vertices:
112
rr
Chapter 3Chapter 3
2D Convex Hulls2D Convex Hulls
Convexity & Convex HullsConvexity & Convex Hulls
A convex combination of points A convex combination of points xx11, ..., x, ..., xkk is a sum of the form is a sum of the form
11xx11+...+ +...+ kkxxkk where where
Convex hull of a set of points is Convex hull of a set of points is the set of all convex the set of all convex combinations of points in the combinations of points in the set.set.
nonconvex polygonnonconvex polygon
convex hull of a point setconvex hull of a point set
10 1 ki andi
Naive Algorithms for Extreme PointsNaive Algorithms for Extreme Points
AlgorithmAlgorithm: INTERIOR POINTS: INTERIOR POINTSfor each i dofor each i do for each j = i dofor each j = i do for each k = j = i dofor each k = j = i do
for each L = k = j = i do for each L = k = j = i do if pif pL L in triangle(pin triangle(pii, p, pjj, p, pkk))
then pthen pLL is nonextreme is nonextreme O(nO(n44))
AlgorithmAlgorithm: EXTREME EDGES: EXTREME EDGESfor each i dofor each i do for each j = i dofor each j = i do for each k = j = i dofor each k = j = i do
if pif pk k is not left or on (pis not left or on (pii, p, pjj))
then (pthen (pi i , p, pjj) is not extreme) is not extreme O(nO(n33))
Gift WrappingGift Wrapping
Use one extreme edge as an Use one extreme edge as an anchor for finding the nextanchor for finding the next
O(nO(n22))
AlgorithmAlgorithm: GIFT WRAPPING: GIFT WRAPPING
ii00 index of the lowest point index of the lowest point
i ii i00repeatrepeat for each j = ifor each j = i Compute counterclockwise angle Compute counterclockwise angle from previous hull edge from previous hull edge k index of point with smallest k index of point with smallest Output (pOutput (pi i , p, pkk) as a hull edge) as a hull edge i ki kuntil i = iuntil i = i00
QuickHullQuickHull
Concentrate on points close to Concentrate on points close to hull boundaryhull boundary
Named for similarity to Named for similarity to Quicksort Quicksort
aa
bb
O(nO(n22))
AlgorithmAlgorithm: QUICK HULL: QUICK HULL
function QuickHull(a,b,S)function QuickHull(a,b,S)
if S = 0 return()if S = 0 return() elseelse c index of point with max distance from abc index of point with max distance from ab A points strictly right of (a,c)A points strictly right of (a,c) B points strictly right of (c,b)B points strictly right of (c,b) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B)return QuickHull(a,c,A) + (c) + QuickHull(c,b,B)
Graham’s AlgorithmGraham’s Algorithm
Points sorted angularly provide Points sorted angularly provide “star-shaped” starting point“star-shaped” starting point
Prevent “dents” as you go via Prevent “dents” as you go via convexity testingconvexity testing
O(nlgn)O(nlgn)
AlgorithmAlgorithm: GRAHAM SCAN, Version B: GRAHAM SCAN, Version B
Find rightmost lowest point; label it pFind rightmost lowest point; label it p00..
Sort all other points angularly about pSort all other points angularly about p00.. In case of tie, delete point(s) closer to pIn case of tie, delete point(s) closer to p00..Stack S (pStack S (p11, p, p00) = (p) = (ptt, p, pt-1t-1); t indexes top); t indexes topi 2i 2while i < n dowhile i < n do
if pif pii is strictly left of p is strictly left of pt-1t-1pptt
then Push(pthen Push(pii, S) and set i i +1, S) and set i i +1else Pop(S)else Pop(S)
Lower Bound of O(nlgn)Lower Bound of O(nlgn)
Worst-case time to find convex hull of n points Worst-case time to find convex hull of n points in algebraic decision tree model is in in algebraic decision tree model is in (nlgn)(nlgn)
Proof uses sorting reduction:Proof uses sorting reduction: Given unsorted list of n numbers: (xGiven unsorted list of n numbers: (x11,x,x2 2 ,…, x,…, xnn)) Form unsorted set of points: (xForm unsorted set of points: (xii, x, xii
22) for each x) for each xii
Convex hull of points produces Convex hull of points produces sorted listsorted list!! Parabola: every point is on convex hullParabola: every point is on convex hull
Reduction is O(n) (which is o(nlgn))Reduction is O(n) (which is o(nlgn)) Finding convex hull of n points is therefore at least Finding convex hull of n points is therefore at least
as hard as sorting n points, so worst-case time is in as hard as sorting n points, so worst-case time is in (nlgn)(nlgn)
Parabola for sorting 2,1,3Parabola for sorting 2,1,3
Incremental AlgorithmIncremental Algorithm
Add points, one at a timeAdd points, one at a time update hull for each new pointupdate hull for each new point
Key step becomes adding a single Key step becomes adding a single point to an existing hull.point to an existing hull.
Idea is extended to 3D in Chapter Idea is extended to 3D in Chapter 4.4.
O(nO(n22))
AlgorithmAlgorithm: INCREMENTAL ALGORITHM: INCREMENTAL ALGORITHM
Let HLet H22 ConvexHull{p ConvexHull{p0 0 , p, p1 1 , p, p2 2 }}
for k 3 to n - 1 dofor k 3 to n - 1 do HHkk ConvexHull{ H ConvexHull{ Hk-1 k-1 U pU pk k }}
can be improved to O(nlgn)can be improved to O(nlgn)
Divide-and-ConquerDivide-and-Conquer
Divide-and-Conquer in a geometric settingDivide-and-Conquer in a geometric setting O(n) merge step is the challengeO(n) merge step is the challenge
Find upper and lower tangentsFind upper and lower tangents Lower tangent: find rightmost pt of A & Lower tangent: find rightmost pt of A &
leftmost pt of B; then “walk it downwards”leftmost pt of B; then “walk it downwards” Idea is extended to 3D in Chapter 4.Idea is extended to 3D in Chapter 4.
AlgorithmAlgorithm: DIVIDE-and-CONQUER: DIVIDE-and-CONQUER
Sort points by x coordinateSort points by x coordinate
Divide points into 2 sets A and B:Divide points into 2 sets A and B:
A contains left n/2 pointsA contains left n/2 points
B contains right n/2 pointsB contains right n/2 points
Compute ConvexHull(A) and ConvexHull(B) recursivelyCompute ConvexHull(A) and ConvexHull(B) recursively
Merge ConvexHull(A) and ConvexHull(B) Merge ConvexHull(A) and ConvexHull(B) O(nlgn)O(nlgn)
AABB
Homework Homework
11 Fri, 2/9 Fri, 2/9 Wed, 2/14 Wed, 2/14 Chapter 1 (O’Rourke)Chapter 1 (O’Rourke) problems 1 & 2problems 1 & 2
Extra credit may be turned in any time during Extra credit may be turned in any time during week of 2/12week of 2/12
22 Mon, 2/12 Mon, 2/12 Wed, 2/21 Wed, 2/21 Chapters 2,3 (O’Rourke)Chapters 2,3 (O’Rourke)problems 1 & 2problems 1 & 2
Extra credit may be turned in any time during Extra credit may be turned in any time during week of 2/21week of 2/21
HW#HW# AssignedAssigned DueDue ContentContent
Machine AccountsMachine Accounts
Each student has an account on my machine: Each student has an account on my machine: minkowski.cs.uml.eduminkowski.cs.uml.edu
Username is the same as your username on CS Username is the same as your username on CS Password is your initials followed by the last 5 digits on Password is your initials followed by the last 5 digits on
the bottom right hand corner of the back of your student the bottom right hand corner of the back of your student id card (1 exception)id card (1 exception)
To remotely log in, use a secure shell (e.g. ssh)To remotely log in, use a secure shell (e.g. ssh) To transfer files, use a secure FTP (e.g. sftpc)To transfer files, use a secure FTP (e.g. sftpc)
Saturn has an sftpc clientSaturn has an sftpc client Code to use with assignments will be there.Code to use with assignments will be there.
Preparing for Homework 2Preparing for Homework 2
Graham Scan 2D Convex Hull CodeGraham Scan 2D Convex Hull Code Background on research problem that Background on research problem that
motivates problem 2 motivates problem 2