CS133 Computational Geometry Convex Hull 4/12/2018 1 Convex Hull - - PowerPoint PPT Presentation

β–Ά
cs133
SMART_READER_LITE
LIVE PREVIEW

CS133 Computational Geometry Convex Hull 4/12/2018 1 Convex Hull - - PowerPoint PPT Presentation

CS133 Computational Geometry Convex Hull 4/12/2018 1 Convex Hull Given a set of n points, find the minimal convex polygon that contains all the points 4/12/2018 2 Convex Hull Properties 4/12/2018 3 Convex Hull Representation The


slide-1
SLIDE 1

CS133

Computational Geometry

Convex Hull

4/12/2018 1

slide-2
SLIDE 2

Convex Hull

Given a set of n points, find the minimal convex polygon that contains all the points

4/12/2018 2

slide-3
SLIDE 3

Convex Hull Properties

4/12/2018 3

ΞΈ

slide-4
SLIDE 4

Convex Hull Representation

The convex hull is represented by all its points sorted in CW/CCW order Special case: Three collinear points

4/12/2018 4

slide-5
SLIDE 5

NaΓ―ve Convex Hull Algorithm

Iterate over all possible line segments A line segment is part of the convex hull if all

  • ther points are to its left

Emit all segments in a CCW order Running time 𝑃 π‘œ3

4/12/2018 5

slide-6
SLIDE 6

NaΓ―ve Convex Hull Algorithm

4/12/2018 6

slide-7
SLIDE 7

Graham Scan Algorithm

4/12/2018 7

slide-8
SLIDE 8

Graham Scan Algorithm

4/12/2018 8

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-9
SLIDE 9

Graham Scan Algorithm

4/12/2018 9

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-10
SLIDE 10

Graham Scan Algorithm

4/12/2018 10

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-11
SLIDE 11

Graham Scan Algorithm

4/12/2018 11

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-12
SLIDE 12

Graham Scan Algorithm

4/12/2018 12

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-13
SLIDE 13

Graham Scan Algorithm

4/12/2018 13

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-14
SLIDE 14

Graham Scan Algorithm

4/12/2018 14

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-15
SLIDE 15

Graham Scan Algorithm

4/12/2018 15

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-16
SLIDE 16

Graham Scan Algorithm

4/12/2018 16

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-17
SLIDE 17

Graham Scan Algorithm

4/12/2018 17

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-18
SLIDE 18

Graham Scan Algorithm

4/12/2018 18

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-19
SLIDE 19

Graham Scan Algorithm

4/12/2018 19

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-20
SLIDE 20

Graham Scan Algorithm

4/12/2018 20

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-21
SLIDE 21

Graham Scan Algorithm

4/12/2018 21

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-22
SLIDE 22

Graham Scan Algorithm

4/12/2018 22

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-23
SLIDE 23

Graham Scan Algorithm

4/12/2018 23

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-24
SLIDE 24

Graham Scan Algorithm

4/12/2018 24

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-25
SLIDE 25

Graham Scan Algorithm

4/12/2018 25

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-26
SLIDE 26

Graham Scan Algorithm

4/12/2018 26

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-27
SLIDE 27

Graham Scan Algorithm

4/12/2018 27

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-28
SLIDE 28

Graham Scan Algorithm

4/12/2018 28

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-29
SLIDE 29

Graham Scan Algorithm

4/12/2018 29

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-30
SLIDE 30

Graham Scan Algorithm

4/12/2018 30

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-31
SLIDE 31

Graham Scan Algorithm

4/12/2018 31

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

slide-32
SLIDE 32

Example

4/12/2018 32

slide-33
SLIDE 33

Graham Scan Pseudo Code

Select the point with minimum y Sort all points in CCW order {p0,p1,…,pn) S = {p0,p1} For i=2 to n

While |S| > 2 && pi is to the right of S-2,S-1

S.pop

S.push(pi)

4/12/2018 33

slide-34
SLIDE 34

Monotone Chain Algorithm

Has some similarities with Graham scan algorithm Instead of sorting in CCW order, it sorts by

  • ne coordinate (e.g., x-coordinates)

4/17/2018 34

slide-35
SLIDE 35

Example

4/17/2018 35

slide-36
SLIDE 36

Pseudo Code

Sort S by x U = {S0} For i = 1 to n

while |U| > 1 && Si is to the left of π‘‰βˆ’2π‘‰βˆ’1

U.pop

U.push(Si)

L = {S0}

While |L| > 1 && Si is to the right of π‘€βˆ’2π‘€βˆ’1

L.pop

L.push(Si)

4/17/2018 36

slide-37
SLIDE 37

Gift Wrapping Algorithm

Start with a point on the convex hull Find more points on the hull one at a time Terminate when the first point is reached back Also knows as Jarvis March Algorithm

4/17/2018 37

slide-38
SLIDE 38

Gift Wrapping Example

4/17/2018 38

slide-39
SLIDE 39

Gift Wrapping Example

4/17/2018 39

slide-40
SLIDE 40

Gift Wrapping Example

4/17/2018 40

slide-41
SLIDE 41

Gift Wrapping Example

4/17/2018 41

slide-42
SLIDE 42

Gift Wrapping Example

4/17/2018 42

slide-43
SLIDE 43

Gift Wrapping Example

4/17/2018 43

slide-44
SLIDE 44

Gift Wrapping Example

4/17/2018 44

slide-45
SLIDE 45

Gift Wrapping Example

4/17/2018 45

slide-46
SLIDE 46

Gift Wrapping Example

4/17/2018 46

slide-47
SLIDE 47

Gift Wrapping Pseudo Code

Gift Wrapping(S)

CH = {} CH << Left most point do

Start point = CH.last End point = CH[0] For each point s ∈ S

If Start point = End Point OR s is to the left of 𝑇𝑒𝑏𝑠𝑒 π‘žπ‘π‘—π‘œπ‘’, πΉπ‘œπ‘’ π‘žπ‘π‘—π‘œπ‘’ End point = s

CH << End point

Running time O(n.k)

4/17/2018 47

slide-48
SLIDE 48

Divide & Conquer Convex Hull

ConvexHull(S)

Splits S into two subsets S1 and S2 Ch1 = ConvexHull(S1) Ch2 = ConvexHull(S2) Return Merge(Ch1, Ch2)

4/17/2018 48

slide-49
SLIDE 49

Merge: Upper Tangent

4/17/2018 49

slide-50
SLIDE 50

Merge: Upper Tangent

4/17/2018 50

slide-51
SLIDE 51

Merge: Upper Tangent

4/17/2018 51

slide-52
SLIDE 52

Merge: Lower Tangent

4/17/2018 52

slide-53
SLIDE 53

Merge: Lower Tangent

4/17/2018 53

slide-54
SLIDE 54

Merge: Lower Tangent

4/17/2018 54

slide-55
SLIDE 55

Merge: Lower Tangent

4/17/2018 55

slide-56
SLIDE 56

Merge: Lower Tangent

4/17/2018 56

slide-57
SLIDE 57

Merge: Lower Tangent

4/17/2018 57

slide-58
SLIDE 58

Merge Step

Upper Tangent(L,R)

Pi = Right most point in L Pj = Left most point in R Do

Done = true While Pi+1 is to the right of π‘žπ‘˜π‘žπ‘—

i++; done = false

While Pj-1 is to the left of π‘žπ‘—π‘žπ‘˜

j--; done = false

4/17/2018 58

slide-59
SLIDE 59

Analysis

Sort step: O(n log n) Merge step: O(n) Recursive part

T(n)=2T(n/2)+O(n) T(n)=O(n log n)

Overall running time O(n log n)

4/17/2018 59

slide-60
SLIDE 60

Incremental Convex Hull

Start with an initial convex hull Add one additional point to the convex hull Given a convex hull CH and a point p, how to compute the convex hull of {CH, p}? Think: Insert an element into a sorted list

4/19/2018 60

slide-61
SLIDE 61

Case 1: p inside CH

4/19/2018 61

slide-62
SLIDE 62

Case 2: p on CH

4/19/2018 62

slide-63
SLIDE 63

Case 3: p outside CH

4/19/2018 63

slide-64
SLIDE 64

Case 3: p outside CH

4/19/2018 64

slide-65
SLIDE 65

Analysis of the Insert Function

Test whether the point is inside, outside, or

  • n the polygon O(n)

Find the two tangents O(n) A more efficient algorithm can have an amortized running time of O(log n)

4/19/2018 65

slide-66
SLIDE 66

Quick Hull

If we can have a divide-and-conquer algorithm similar to merge sort … why not having an algorithm similar to quick sort? Sketch

Find a pivot Split the points along the pivot Recursively process each side

4/19/2018 66

slide-67
SLIDE 67

Quick Hull

4/19/2018 67

slide-68
SLIDE 68

Quick Hull

4/19/2018 68

How to split the points across the line segment?

slide-69
SLIDE 69

Quick Hull

4/19/2018 69

How to select the farthest point?

slide-70
SLIDE 70

Quick Hull

4/19/2018 70

slide-71
SLIDE 71

Quick Hull

4/19/2018 71

slide-72
SLIDE 72

Quick Hull

4/19/2018 72

How to split the points into three subsets?

slide-73
SLIDE 73

Quick Hull

4/19/2018 73

slide-74
SLIDE 74

Quick Hull

4/19/2018 74

slide-75
SLIDE 75

Quick Hull

4/19/2018 75

slide-76
SLIDE 76

Quick Hull

4/19/2018 76

slide-77
SLIDE 77

Quick Hull

4/19/2018 77

slide-78
SLIDE 78

Quick Hull

4/19/2018 78

slide-79
SLIDE 79

Quick Hull

4/19/2018 79

slide-80
SLIDE 80

Example

4/19/2018 80

slide-81
SLIDE 81

Running Time Analysis

π‘ˆ π‘œ = π‘ˆ π‘œ1 + π‘ˆ π‘œ2 + 𝑃 π‘œ Worst case π‘œ1 = π‘œ βˆ’ 𝑙 or π‘œ2 = π‘œ βˆ’ 𝑙, where 𝑙 is a small constant (e.g., k=1)

π‘ˆ π‘œ = 𝑃 π‘œ2

Best case π‘œ1 = 𝑙 and π‘œ2 = 𝑙, where 𝑙 is a small constant

In this case, most of the points are pruned π‘ˆ π‘œ = 𝑃 π‘œ

Average case, π‘œ1 = π›½π‘œ and π‘œ2 = π›Ύπ‘œ, where 𝛽 < 1 and 𝛾 < 1

π‘ˆ π‘œ = 𝑃 π‘œ log π‘œ

4/19/2018 81