Upload
dian
View
47
Download
0
Tags:
Embed Size (px)
DESCRIPTION
UMass Lowell Computer Science 91.504 Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2007. Lecture 3 Chapter 3: 2D Convex Hulls Friday, 2/9/07. Chapter 3. Definitions Gift Wrapping Graham Scan QuickHull Incremental Divide-and-Conquer Lower Bound in W (nlgn). - PowerPoint PPT Presentation
Citation preview
UMass Lowell Computer Science 91.504 Advanced Algorithms
Computational Geometry Prof. Karen Daniels
Spring, 2007
Lecture 3Lecture 3Chapter 3: 2D Convex HullsChapter 3: 2D Convex Hulls
Friday, 2/9/07Friday, 2/9/07
Chapter 32D Convex Hulls2D Convex Hulls
DefinitionsDefinitionsGift WrappingGift WrappingGraham ScanGraham Scan
QuickHullQuickHullIncrementalIncremental
Divide-and-ConquerDivide-and-ConquerLower Bound in Lower Bound in (nlgn)(nlgn)
Convexity & 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 the Convex hull of a set of points is the set of all convex combinations of set of all convex combinations of points in the set.points in the set.
nonconvex polygonnonconvex polygon
convex hull of a point setconvex hull of a point set
10 1 ki andi
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C
source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.
We will We will construct construct boundaryboundary of convex of convex hull.hull.
Naive 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))
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C
Algorithms: 2D Gift 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 WRAPPINGii00 index of the lowest point index of the lowest pointi 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
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C
Gift Wrapping source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.
33.9
Output SensitivityOutput Sensitivity: O(n: O(n22) run-time is actually O(nh) ) run-time is actually O(nh) where h is the number of vertices of the convex hull.where h is the number of vertices of the convex hull.
Algorithms: 3D Gift Wrapping
CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html
O(nO(n22)) time time [output sensitive: O(nF) for F faces on hull][output sensitive: O(nF) for F faces on hull]
Algorithms: 2D QuickHull
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 HULLfunction 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)
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C
finds one of upper or lower hullfinds one of upper or lower hull
cc
AA
Algorithms: 3D QuickHull
CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html
Algorithms for
Qhull: http://www.qhull.orgQhull: http://www.qhull.org
Convex Hull Convex Hull boundary is boundary is intersection of intersection of hyperplanes, so hyperplanes, so worst-case worst-case combinatorial size combinatorial size (not necessarily running (not necessarily running time)time) complexity is complexity is in:in: )( 2/dn
82 d
Graham’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 BFind 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)
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C
““multipop”multipop”
pp00
Graham Scan
source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.
Graham Scan
source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.
33.7
Graham Scan
source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.
33.7
Graham Scan
source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.
Graham Scan
source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.
Algorithms: 2D Incremental
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 point Key step becomes adding a single point to an existing hull.to an existing hull. Find 2 tangentsFind 2 tangents
Results of 2 consecutive LEFT tests differResults of 2 consecutive LEFT tests differ Idea can be extended to 3D.Idea can be extended to 3D.
O(nO(n22))
AlgorithmAlgorithm: INCREMENTAL ALGORITHM: INCREMENTAL ALGORITHMLet 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)
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C
Algorithms: 3D Incremental
CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html
O(nO(n22)) time time
Algorithms: 2D Divide-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 can be extended to 3D.Idea can be extended to 3D.
AlgorithmAlgorithm: DIVIDE-and-CONQUER: DIVIDE-and-CONQUERSort points by x coordinateSort points by x coordinateDivide 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 pointsB contains right n/2 pointsB contains right n/2 points
Compute ConvexHull(A) and ConvexHull(B) recursivelyCompute ConvexHull(A) and ConvexHull(B) recursivelyMerge ConvexHull(A) and ConvexHull(B) Merge ConvexHull(A) and ConvexHull(B) O(nlgn)O(nlgn)
AA BB
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C
Algorithms: 3D Divide and Conquer
CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html
O(n log n)O(n log n) time ! time !
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 in o(nlgn))Reduction is O(n) (which is in 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
source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C