1 / 60

Computational Geometry 2D Convex Hulls

Computational Geometry 2D Convex Hulls. Joseph S. B. Mitchell Stony Brook University. Chapter 2: Devadoss -O’Rourke. p. q. p. convex. non-convex. q. Convexity. Extreme points in red. r. p. q. Set X is convex if p,q X  pq  X

jobregon
Download Presentation

Computational Geometry 2D Convex Hulls

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computational Geometry2D Convex Hulls Joseph S. B. Mitchell Stony Brook University Chapter 2: Devadoss-O’Rourke

  2. p q p convex non-convex q Convexity Extreme points in red r p q Set X is convexif p,qX  pq X Point p X is an extreme point if there exists a line (hyperplane) through p such that all other points of X lie strictly to one side

  3. Convex Hull

  4. Convex Hull, Extreme Points

  5. Convex Hull: Equivalent Def Convex combination of points:

  6. Convex Hull: Equivalent Defs

  7. Equivalent Definitions of Convex Hull, CH(X) Devadoss-O’Rourke Def {all convex combinations of d+1 points of X } [Caratheodory’sThm] (in any dimension d) Set-theoretic “smallest” convex set containing X. In 2D: min-area (or min-perimeter) enclosing convex body containing X In 2D:

  8. Convex Hull in 2D Fact: If X=S is a finite set of points in 2D, then CH(X) is a convex polygon whose vertices (extreme points) are points of S.

  9. Fundamental Algorithmic Problem: 2D Convex Hulls p2 More generally: CH(polygons) p7 p4 p8 p3 p1 p6 p5 p9 Output: (9,6,4,2,7,8,5) Input: n points S = (p1, p2, …, pn) Output: A boundary representation, e.g., ordered list of vertices (extreme points), of the convex hull, CH(S), of S (convex polygon)

  10. Convex Hull Problem in 2D

  11. Computational Complexity Function T(n) is O(f(n)) if there exists a constant C such that , for sufficiently large n, T(n) < C f(n)

  12. Comparing O(n), O(n log n), O(n2) Function T(n) is O(f(n)) if there exists a constant C such that , for sufficiently large n, T(n) < C f(n) n n log n n² 210 10³ 10 • 210  104 220  106 220  106 20 • 220  2 • 107 240 1012 Interactive Processingn log n algorithms n² algorithms n = 1000 yes ? n = 1000000 ? no

  13. 2D Convex Hull Algorithms [DO] Section 2.2 • O(n4) simple, brute force (but finite!) • O(n3) still simple, brute force • O(n2) incremental algorithm • O(nh) simple, “output-sensitive” • h = output size (# vertices) • O(n log n) worst-case optimal (as fcn of n) • O(n log h) “ultimate” time bound (as fcn of n,h) • Randomized, expected O(n log n)

  14. Lower Bound [DO] Section 2.5 y= x2 (xi,xi2 ) From SORTING: xi Note: Even if the output of CH is not required to be an ordered list of vertices (e.g., just the # of vertices), (n log n) holds Lower bound: (n log n) As function of n and h: (n log h) holds

  15. Lower Bound [DO] Section 2.5 computing the ordered convex hull of n points in the plane.

  16. Lower Bound [DO] Section 2.5 computing the ordered convex hull of n points in the plane. An even stronger statement is true:

  17. Primitive Computation c b Left( a, b, c ) = TRUE  ab  ac > 0 c is left of ab a • “Left” tests: sign of a cross product (determinant), which determines the orientation of 3 points • Time O(1) (“constant”)

  18. SuperStupidCH: O(n4) q s p O(n3) r O(n) • Fact: If s∆pqr, then s is not a vertex of CH(S) •  p •  q  p •  r  p,q •  s  p,q,r: If s  ∆pqr then mark s as NON-vertex • Output: Vertices of CH(S) • Can sort (O(n log n) ) to get ordered

  19. StupidCH: O(n3) q p O(n2) r O(n) Applet by Snoeyink • Fact: If all points of S lie strictly to one side of the line pq or lie in between p and q, then pq is an edge of CH(S). •  p •  q  p •  r  p,q: If r  redthen mark pq as NON-edge (ccw) • Output: Edges of CH(S) • Can sort (O(n log n) ) to get ordered Caution!! Numerical errors require care to avoid crash/infinite loop!

  20. Incremental Algorithm [DO] Section 2.2

  21. Incremental Algorithm Sort points by x-coordinate O(n log n) Build CH(X), adding pts left to right

  22. Incremental Algorithm

  23. Incremental Algorithm

  24. O(nh) : Gift-Wrapping Jarvis March O(n) per step h steps Total: O(nh) r q p Key observation: Output-sensitive! Idea: Use one edge to help find the next edge. Output: Vertices of CH(S) Demo applet of Jarvis march

  25. Gift-Wrapping [DO] Section 2.4

  26. Gift-Wrapping [DO] Section 2.4

  27. O(n log n) : Graham Scan O(n) O(n log n) O(n) CH so far • Idea: Sorting helps! • Start with vlowest(min-y), a known vertex • Sort S by angle about vlowest • Graham scan: • Maintain a stack representing (left-turning) CH so far • If pi is left of last edge of stack, then PUSH • Else, POP stack until it is left, charging work to popped points vlowest Demo applet

  28. Graham Scan Red points form right turn, so are discarded [DO] Section 2.4

  29. Graham Scan [DO] Section 2.4

  30. Sorted points: Graham Scan [O’Rourke, Chapter 3]

  31. [O’Rourke, Chapter 3]

  32. [O’Rourke, Chapter 3] Stack History

  33. O(n log n) : Divide and Conquer Time O(n) Time 2T(n/2) Time O(n) Sleft Sright Time: T(n)  2T(n/2) + O(n)  T(n) = O(n log n) Split S into Sleftand Sright , sizes n/2 Recursively compute CH(Sleft), CH(Sright) Merge the two hulls by finding upper/lower bridges in O(n), by “wobbly stick” Demo applet

  34. Divide and Conquer [DO] Section 2.6

  35. Divide and Conquer [DO] Section 2.6

  36. Divide and Conquer [DO] Section 2.6

  37. QuickHull c = point furthest from ab c Discard points in abc B A Worst-case: O(n2 ) Avg: O(n) b a Works well in higher dimensions too! S • QuickHull(a,b,S) to compute upperhull(S) • If S=, return () • Else return (QuickHull(a,c,A), c, QuickHull(c,b,B)) Qhull website Qhull, Brad Barber (used within MATLAB)

  38. QuickHull • Applet (programmed by Jeff So) • Applet (by Lambert) • When is it “bad”? (see hw2) • If no points are discarded (in abc), at each iteration, and • The “balance” may be very lop-sided (between sets A and B; in fact, one set could be empty, at every iteration!)

  39. QuickHull [David Mount lecture notes, Lecture 3]

  40. O(n log n) : Incremental Construction AMS 545 / CSE 555 Point location test: O(log n) Binary search: O(log n) • Add points in the order given: v1 ,v2 ,…,vn • Maintain current Qi= CH(v1 ,v2 ,…,vi) • Add vi+1: • If vi+1 Qi , do nothing • Else insert vi+1 by finding tangencies, updating the hull • Worst-case cost of insertion: O(log n) • But, uses complex data structures

  41. O(n log n) : Randomized Incremental AMS 545 / CSE 555 • Add points in random order • Keep current Qi= CH(v1 ,v2 ,…,vi) • Add vi+1: • If vi+1 Qi , do nothing • Else insert vi+1 by finding tangencies, updating the hull • Expected cost of insertion: O(log n)

  42. Add vi+1 Qi: • Start from “conflict” edge e, and walk cw/ccw to establish new tangencies from vi+1 , charging walk to deleted vertices • Rebucket points in affected cones • (update lists for each bucket) • Total work: O(n) + rebucketing work • E(rebucket cost for vjat step i) = • O(1)  P(rebucket)  O(1)  (2/i) = O(1/i) • E(total rebucket cost for vj) =  O(1/i) = O(log n) • Total expected work = O(n log n) vj AMS 545 / CSE 555 e vi+1 Backwards Analysis: vj was just rebucketed iff the last point inserted was one of the 2 endpoints of the (current) conflict edge, e, for vj Each uninsertedvj Qi(j>i+1) points to the bucket (cone) containing it; each cone points to the list of uninsertedvj Qiwithin it(with its conflict edge)

  43. Output-Sensitive: O(n log h) h = output size AMS 545 / CSE 555 So, O(n log h) is BEST POSSIBLE, as function of n and h !! • The “ultimate” convex hull (in 2D) • “Marriage before Conquest” : O(n log h) • Lower bound (n log h) [Kirkpatrick & Seidel’86] • Simpler [Chan’95] • 2 Ideas: • Break point set S into groups of appropriate size m (ideally, m = h) • Search for the “right” value of m ( =h, which we do not know in advance) by repeated squaring

  44. Chan’s Algorithm = O(n log h) AMS 545 / CSE 555 = O( h (n/h) log h) = O(n log h) v O(n ( log (221) + log (222) + log (223) + … log (22 log (log (h))) = O(n (21 + 22 + 23 + … + 2log (log (h)) )) = O(n (2 log h)) = O(n log h) v • Break S into n/m groups, each of size m • Find CH of each group (using, e.g., Graham scan): • O(m log m) per group, so total O((n/m) m log m) = O(n log m) • Gift-wrap the n/m hulls to get overall CH: • At each gift-wrap step, when pivoting around vertex v • find the tangency point (binary search, O(log m)) to each group CH • pick the smallest angle among the n/m tangencies: • O( h (n/m) log m) • Hope: m=h • Try m = 4, 16, 256, 65536,…

  45. CH of Simple Chains/Polygons 1 2 n Input: ordered list of points that form a simple chain/cycle Importance of simplicity (noncrossing, Jordan curve) as a means of “sorting” (vs. sorting in x, y) Melkman’s Algorithm: O(n) (vs. O(n log n) or O(n log h))

  46. Melkman’s Algorithm vt-1 vt vt-1 vb vi vi vt vb vb+1 vb+1 Simplicity helps! Keep hull in DEQUE: <vb,vb+1 ,…,vt-1 ,vt=vb> While Left(vb ,vb+1 ,vi) and Left(vt-1 ,vt ,vi) i i+1 Remove vb+1 , vb+2 ,… and vt-1 , vt-2 ,… until convexity restored New vb =vt = vi Claim: Simplicity assures that the only way for the chain to exit the current hull is via pockets vb vb+1or vt-1vt . Time: O(n), since O(1) per insertion

  47. Melkman’s Algorithm

  48. Melkman’s Algorithm

  49. Melkman’s Algorithm

  50. Expected Size of CH

More Related