Presentation is loading. Please wait.

Presentation is loading. Please wait.

A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave.

Similar presentations


Presentation on theme: "A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave."— Presentation transcript:

1 A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave. Convex p q R 1 p q R 2 Concave

2 12 3 4

3 The convex hull CH(Q) of a set Q is the smallest convex region that contains Q. Rubber band When Q is finite, its convex hull is the unique convex polygon whose vertices are from Q and that contains all points of Q.

4 Input: a set P = { p, p, …, p } of points Output: a list of vertices of CH(P) in counterclockwise order. 1 2 n Example Output: p, p, p, p, p, p. 5 9 2 8 10 7 8 p p p p p p p p p p 9 2 10 5 76 1 3 4

5 For every edge both endpoints p, q  P. p q All other points in P lie to the same side of the line passing through p and q

6 p r q Nearly colinear points p, q, r. p to the left of qr. q to the left of rp. r to the left of qp. All three accepted as edges! Not robust – the algorithm could fail with small numerical error.

7 p polar angle x y q r

8 p 0 p p p p p p p p p p 1 2 3 4 p 5 6 7 8 9 10 11 (with the minimum y-coordinate) Labels are in the polar angle order. (What if two points have the same polar angle?) How to break a tie? Sort by polar angle. handling degeneracies

9 p p p p p p p p p p p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 2

10 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 3

11 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 4

12 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 4 p 5

13 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 4 p 6

14 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 4 p 6 p 7 p 8

15 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 4 p 6 p 7

16 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 4 p 6 p 9 p 10

17 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 11 p p p S 0 1 4 p 6 p 9 p

18 p p p p p p p p pp p 0 1 2 3 4 p 5 6 7 8 9 10 11 p p p S 0 1 4 p 6 p 9 p

19 p p p p 0    j i k p p p 0    i l Every point in P is pushed onto S once Non-vertices of CH(P) determined so far are popped vertices of CH(P) in the counter- clockwise order. candidates for vertices of CH(P) p 0 p p 1 2 start p p 0    s finish p p p 0 j i   

20 Graham-Scan(P) let p be the point in P with minimum y-coordinate let  p, p, …, p  be the remaining points in P sorted in counterclockwise order by polar angle around p. Top[S]  0 Push(p, S) for i  3 to n  1 do while p makes a nonleft turn from the line segment determined by Top(S) and Next-to-Top(S) do Pop(S) Push(S, p ) return S 0 1 2 n–1 0 1 2 i i 0

21 Claim 1 Each point popped from stack S is not a vertex of CH(P). p p p p 0 i j k p p p p 0 i j k Two cases when p is popped: j In neither case can p become a vertex of CH(P). j Proof

22 Claim 2 Graham-Scan maintains the invariant that the points on stack S always form the vertices of a convex polygon in counterclockwise order. Popping a point from S preserves the invariant. The region containing p i The invariant still holds. ProofThe claim holds right after initialization of S when p, p, p form a triangle (which is obviously convex). 0 1 2 Consider a point p being pushed onto S. i p 0 p j p i

23 Theorem If Graham-Scan is run on a set P of at least three points, then a point of P is on the stack S at termination if and only if it is a vertex of CH(P).

24 The running time of Graham’s Scan is O(n lg n). #operations time / operation total Push n O(1)  (n) Pop  n  2 O(1) O(n) Sorting 1 O(n lg n) O(n lg n) Why? Finding p 0 1  (n)  (n)

25 A “package wrapping” technique p 4 p 0(lowest point) p 1 (smallest polar angle w.r.t. p ) 0 p 5 (smallest polar angle w.r.t. p ) 4 Right chain p 6 (smallest polar angle w.r.t. p ) 5 p 2 (smallest polar angle w.r.t. p ) 1 p 3 (smallest polar angle w.r.t. p ) 2 Left chain

26 Let h be the number of vertices of the convex hull. For each vertex, finding the point with the minimum Polar angle, that is, the next vertex, takes time O(n). Comparison between two polar angles can be done using cross product. Thus O(nh) time in total.


Download ppt "A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave."

Similar presentations


Ads by Google