1 / 20

Polar Angle

Polar Angle. y. q. polar angle. p. x. r. p. p. 6. 9. p. p. 7. 4. p. 11. p. p. 8. p. 5. 10. p. 3. p. p. 2. 1. p. 0. An Example of Graham Scan. Sort by polar angle. (with the minimum y -coordinate). How to break a tie?. Labels are in the polar angle order.

blythe
Download Presentation

Polar Angle

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. Polar Angle y q polar angle p x r

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

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

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

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

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

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

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

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

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

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

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

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

  14. The Graham Scan Algorithm Graham-Scan(P) let p be the point in P with minimumy-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) Push(p , S) Push(p , S) fori  3 ton  1 do whilep makes a nonleft turn from the line segment determined by Top(S) and Next-to-Top(S) doPop(S) Push(S, p ) returnS 0 1 2 n–1 0 0 1 2 i i

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

  16. The 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 j The region containing p i p i p 0 Claim 2Graham-Scan maintains theinvariant that the points on stack S always form the vertices of a convex polygon in counterclockwise order. Proof Popping a point from S preserves the invariant. The invariant still holds.

  17. Correctness of Graham’s Scan TheoremIf 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).

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

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

  20. Running Time of Jarvis’s March 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. ThusO(nh)time in total.

More Related