Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O’Rourke (Chap. 3)

Similar presentations


Presentation on theme: "1 Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O’Rourke (Chap. 3)"— Presentation transcript:

1 1 Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O’Rourke (Chap. 3)

2 2 Outline Definitions of CH Algorithms for CH Analysis of algorithms

3 3 Convex Hull Definition of convexity Convex hull of a point set S, CH(S) Smallest convex set containing S Intersection of all convex sets containing S 凸包 (Convex Hull)

4 4 Convex Hull Why computing CH? Many reasons; e.g., faster collision detection How to compute CH? Good solutions come from:  A thorough understanding of the geometric properties of the problem  Proper application of algorithmic techniques and data structures

5 5 General Steps Sketch your problem in general position Observe the desired output and reason about the possible steps to get to the goal Check for degeneracy Time/resource complexity General case Best/worst cases

6 6 Computing CH … of a finite set P of n points in 2D Geometric intuition: Rubberband analogy Representation: Input: point set Output: CH(P): CW- ordered point set

7 7 Observation Def: convex edgesIdea: Search through all pairs of points for convex edges Form a loop

8 8 Naïve Algorithm You can add a break here if you like …

9 9 Analysis of Naïve Algorithm Assumption: points are in general position (usually this is done first to simplify the code) (consider the degenerate cases later) How to compute “lie to the left of directed line”? Complexity analysis: O(n 3 ) (n 2 –n)/2 pairs, each with n–2 other points to examine High complexity due to: simply translate geometric insight into an algorithm in a brute-force manner

10 10 Considering Degeneracy Collinearity: Modify the test to “all points to the right, or on the line” Does this solve the problem?!

11 11 Degenerate Case (cont) Consider numerical inaccuracy Two possibilities:

12 12 Jarvis’ March (Gift Wrapping) A modification of naïve algorithm Start at some extreme point, which is guaranteed to be on the hull. At each step, test each of the points, and find the one which makes the smallest right-hand turn. That point has to be the next one on the hull. The final CW loop is the CH.

13 13 Jarvis’ March (cont) Complexity Crude count: O(n 2 ) Output sensitive O(nh), h:# of segments on the hull Worst case

14 14 A Better Algorithm Sort by x-coord The extreme points must be on the CH Goal: in 2 linked lists Upper hull: p1 to pn Lower hull: pn to p1 Idea: In CW manner, always making right turns If fail to turn right, delete previous point until the turn is correct.

15 15

16 16 Step-by-step 1 2 4 8 6 7 9 5 3 [1,2]

17 17 Step-by-step 1 2 4 8 6 7 9 5 3 [1,2,3]

18 18 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3]

19 19 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,4]

20 20 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,4,5]

21 21 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,5]

22 22 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,5,6]

23 23 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,5,6,7]

24 24 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,5,7]

25 25 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,7]

26 26 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,7,8]

27 27 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,7,8,9]

28 28 Step-by-step 1 2 4 8 6 7 9 5 3 [1,3,7,9] Upper hull completed

29 29 Algorithm (cont) This is a variation of Graham Scan Proof of correctness: p.8 Complexity analysis: O(n log n) Lexicographical sorting of points: O(n log n) Computation of lower hull: O(n)  Consider the for and while

30 30 Consider Degeneracy Again … Effects on sorting Lexico. ordering Effects on making turns…

31 31 Other Version of Graham Scan 1. Find an extreme point. This point will be the pivot, is guaranteed to be on the hull, and is chosen to be the point with smallest y coordinate. 2. Sort the points in order of increasing angle about the pivot. We end up with a star-shaped polygon (one in which one special point, in this case the pivot, can "see" the whole polygon). 3. Build the hull, by marching around the star-shaped poly, adding edges when we make a left turn, and back-tracking when we make a right turn.

32 32 Graham Scan (ver2) Also handles collinearity

33 33 Incremental Algorithm Suitable for dynamic CGeom and 3D hull If p n  CH n-1, CH n =CH n-1 Else Find two tangents, update CH n

34 Incremental Algorithm Input: a set of points P in 2D Output: a list L containing the points of CH(P) in CCW order 1. Take first three points of P to form a triangle 2. For i = 4 to n If (p i is in CH i-1 ) do nothing Else  FindTangent (p i, CH i-1 )  t1, t2  Replace the items {t2 … t1} in L by {t2, p i, t1} 34 t1 t2 CH i-1 pipi

35 FindTangent (p, CH) (Go through all points in CH circularly) For each point p i If XOR (p is left_or_on (p i-1,p i ), p is left_or_on(p i,p i+1 )) Mark p i as the tangent point (There will be two tangent points) Determine t1, t2 35 t1 t2 CH i-1 pipi

36 36 Incremental Algorithm (cont) Finding Tangents … Analysis

37 37 Quick Hull Discard points in the extreme quadrilateral

38 38 Quick Hull (cont) Time complexity: Find extreme point c: O(n) Cost of recursive call:  T(n) = O(n) + T(|A|) + T(|B|) Best case: |A| = |B| = n/2  T(n) = 2T(n/2) + O(n); T(n) = O(n log n) Worst case: |A| = 1, |B| = n-1  T(n) = T(n-1) + O(n); T(n) = O(n 2 )

39 39 Divide and Conquer Algorithm Computing 3D hull: Graham scan (probably not ∵ angle sort ) Preparata and Hong (1977) T(n) = 2T(n/2) + O(n); T(n) = O(n log n) a-1 & a+1 at left side of ab b-1 & b+1 at left side of ab

40 40 Extend to 3D

41 41 Floating Point Inaccuracies Handled by Interval arithmetic Exact (rational) arithmetic

42 42 Interval arithmetic Ref: http://www.eng.mu.edu/corlissg/VC02/READ_ME.html

43 43 Exact Math Rational arithmetic (never floating point) In[6]:= 1/12 - 7/9 + 31/36 Out[6]= - 1/6 The Exact Arithmetic Competition: Level 0 Tests Ref: XRXR

44 44 Exercise From this applet, develop a Graham scan algorithm that returns a CW-ordered convex hullapplet Express the algorithm in pseudocode. Make sure it works for general position and degenerate cases (shown right) Run your example on test cases (general position and degeneracies) Explain the correctness and time complexity of divide-and-conquer algorithm

45 45

46 46 More reference on the web.


Download ppt "1 Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O’Rourke (Chap. 3)"

Similar presentations


Ads by Google