Presentation is loading. Please wait.

Presentation is loading. Please wait.

Convex Sets & Concave Sets

Similar presentations


Presentation on theme: "Convex Sets & Concave Sets"— Presentation transcript:

1 Convex Sets & Concave Sets
A planar region 𝑅 is called convex if and only if for any pair of points 𝑝, 𝑞 in 𝑅, the line segment 𝑝𝑞 lies completely in 𝑅. Otherwise, it is called concave. 𝑝 𝑞 𝑅 2 Concave Convex 𝑝 𝑞 𝑅 1

2 An Example 4 1 2 3 Regions 1 & 2: convex Regions 3 & 4: concave

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

4 Degenerate Cases ♦ The convex hull of a single point is itself.
♦ The convex hull of several collinear points is the line segment joining the two extreme points.

5 The Convex Hull Problem
Input: a set 𝑃 = { 𝑝 1 , 𝑝 2 , …, 𝑝 𝑛 } of points Output: a list of vertices of CH(𝑃) in counterclockwise order. (direction of traversal about the outward axis with the interior on the left) Example 𝑝 1 𝑝 6 𝑝 10 𝑝 7 𝑝 8 𝑝 2 𝑝 5 𝑝 9 𝑝 4 𝑝 3 Output: 𝑝 5 , 𝑝 9 , 𝑝 2 , 𝑝 8 , 𝑝 10 , 𝑝 7 .

6 Edges of a Convex Hull For every edge with endpoints 𝑝, 𝑞 ∈ 𝑃.
All other points in 𝑃 lie to the same side of the line passing through 𝑝 and 𝑞 q p

7 A Slow Convex Hull Algorithm
𝐸 ≠ {} // set of directed edges of CH(𝑃) that bounds the // points of P on the right. for every ordered pair (𝑝, 𝑞), where 𝑝, 𝑞 ∈ 𝑃 and 𝑝 ≠ 𝑞 // ( 𝑛 2 ) pairs do valid  true for every point 𝑟 ≠ 𝑝 or 𝑞 // 𝑛 −2 such points do if 𝑟 lies to the right of 𝑝𝑞 or collinear with 𝑝 and 𝑞 but not on 𝑝𝑞 then valid  false if valid then 𝐸 ≠ 𝐸 ∪ { 𝑝𝑞 } // 𝑝𝑞 and 𝑞𝑝 cannot be both in 𝐸 From 𝐸 construct a list 𝐿 of vertices of CH(𝑃), sorted in counterclockwise order. // 𝑂( 𝑛 2 ) improvable to 𝑂(𝑛 log 𝑛 ) return L 𝑝 𝑞 𝑟 Running time ( 𝒏 𝟑 )

8 Polar Angle 𝑦 𝑞 polar angle p 𝑥 𝑟

9 Graham Scan 1) Select the node with the smallest 𝑦 coordinate. 𝑝 0
This node will be a vertex of the convex hull.

10 Tie Breaking (1) When more than one point has the smallest 𝑦 coordinate, pick the leftmost (or rightmost) one. 𝑝 0

11 Sorting by Polar Angle 2) Sort by polar angle with respect to 𝑝 0 .
𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑝 0 Labels are in the polar angle order.

12 No Polar Angle Evaluation
𝑝 0 is the lowest (and leftmost) all polar angles ∈ 0, 𝜋 . 𝐔𝐬𝐞 𝐜𝐫𝐨𝐬𝐬 𝐩𝐫𝐨𝐝𝐮𝐜𝐭! 𝑝 𝑖 < 𝑝 𝑗 if 𝑝 0 𝑝 𝑖 × 𝑝 0 𝑝 𝑗 >0 𝑝 𝑖 𝑝 𝑗 𝑝 0

13 Tie Breaking (2) What if 𝑝 0 , 𝑝 𝑖 , 𝑝 𝑗 are on the same line?
Order them by distance from 𝑝 0 . 𝑝 𝑖 < 𝑝 𝑗 if and 𝑝 0 𝑝 𝑖 × 𝑝 0 𝑝 𝑗 =0 𝑝 0 𝑝 𝑖 <| 𝑝 0 𝑝 𝑗 | 𝑝 0 𝑝 𝑗 𝑝 𝑖 No square roots. Use dot product! 𝑝 0 𝑝 𝑖 ∙ 𝑝 0 𝑝 𝑖 < 𝑝 0 𝑝 𝑗 ∙ 𝑝 0 𝑝 𝑗

14 Point Elimination When multiple points have the same polar angle, keep the one furthest from 𝑝 0 . Remove the rest since they cannot possibly be the hull vertices. 𝑝 0 furtherest remove 𝑝 𝑗 𝑝 𝑖

15 Stack Initialization 3) Scan points in the increasing order of polar angle, maintaining a stack. 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑝 0 𝑝 2 𝑝 1 𝑆

16 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑆 𝑝 3 𝑝 1 𝑝 0

17 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑆 𝑝 4 𝑝 1 𝑝 0

18 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑆 𝑝 5 𝑝 4 𝑝 1 𝑝 0

19 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑆 𝑝 6 𝑝 4 𝑝 1 𝑝 0

20 𝑆 𝑝 8 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑝 7 𝑝 6 𝑝 4 𝑝 1 𝑝 0

21 𝑆 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑝 7 𝑝 6 𝑝 4 𝑝 1 𝑝 0

22 𝑆 𝑝 10 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑝 9 𝑝 6 𝑝 4 𝑝 1 𝑝 0

23 𝑆 𝑝 11 𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑝 9 𝑝 6 𝑝 4 𝑝 1 𝑝 0

24 Finish S 𝑝 11 𝑝 6 𝑝 9 𝑝 4 𝑝 9 𝑝 11 𝑝 7 𝑝 6 𝑝 3 𝑝 8 𝑝 4 𝑝 5 𝑝 10 𝑝 1
𝑝 0 𝑝 8 𝑝 10 𝑝 9 𝑝 7 𝑝 6 𝑝 4 𝑝 3 𝑝 1 𝑝 2 𝑝 11 𝑝 5 𝑝 9 𝑝 6 𝑝 4 𝑝 1 𝑝 0

25 Graham’s Scan 𝑝 𝑗 𝑝 𝑖 𝑝 0 𝑝 𝑘 𝑝 𝑠 𝑝 0 finish 𝑝 𝑗 𝑝 𝑖 𝑝 0 𝑝 0 𝑝 𝑖 𝑝 𝑙
Non-vertices of CH(𝑃) determined so far are popped candidates for vertices of CH(𝑃) 𝑝 𝑠 𝑝 0 finish 𝑝 𝑗 𝑝 𝑖 𝑝 0 𝑝 0 𝑝 𝑖 𝑝 𝑙 𝑝 0 𝑝 2 𝑝 1 start Every point in 𝑃 is pushed onto 𝑆 once vertices of CH(𝑃) in the counter- clockwise order.

26 The Graham Scan Algorithm
let 𝑝 0 be the point in 𝑃 with minimum 𝑦-coordinate let  𝑝 1 , 𝑝 2 , …, 𝑝 𝑛−1  be the remaining points in 𝑃 sorted in counterclockwise order by polar angle around 𝑝 0 . Top[𝑆]  0 Push( 𝑝 0 , 𝑆) Push( 𝑝 1 , 𝑆) Push( 𝑝 2 , 𝑆) for 𝑖 = 3 to 𝑛 − 1 do while 𝑝 𝑖 makes a nonleft turn from the line segment determined by Top(𝑆) and Next-to-Top(𝑆) do Pop(𝑆) Push(𝑆, 𝑝 𝑖 ) return 𝑆

27 Running time #operations time / operation total Finding 1 (𝑛) (𝑛)
𝑝 0 (𝑛) (𝑛) Sorting 𝑂(𝑛 log 𝑛 ) O(𝑛 log 𝑛 ) Push 𝑛 𝑂(1) (𝑛) Pop  𝑛 − 𝑂(1) 𝑂(𝑛) Why? The running time of Graham’s Scan is 𝑶(𝒏 log 𝒏 ).

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

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

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

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

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

33 Running Time of Jarvis’s March
Let ℎ 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 𝑂(𝑛). Comparison between two polar angles can be done using cross product. Thus 𝑶(𝒏𝒉) time in total.


Download ppt "Convex Sets & Concave Sets"

Similar presentations


Ads by Google