CS133 Computational Geometry Convex Hull 1 Convex Hull Given a - - PowerPoint PPT Presentation

β–Ά
cs133
SMART_READER_LITE
LIVE PREVIEW

CS133 Computational Geometry Convex Hull 1 Convex Hull Given a - - PowerPoint PPT Presentation

CS133 Computational Geometry Convex Hull 1 Convex Hull Given a set of n points, find the minimal convex polygon that contains all the points 2 Convex Hull Properties 3 Convex Hull Representation The convex hull is represented by all


slide-1
SLIDE 1

CS133

Computational Geometry

Convex Hull

1

slide-2
SLIDE 2

Convex Hull

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

2

slide-3
SLIDE 3

Convex Hull Properties

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

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

5

slide-6
SLIDE 6

NaΓ―ve Convex Hull Algorithm

6

slide-7
SLIDE 7

Graham Scan Algorithm

7

slide-8
SLIDE 8

Graham Scan Algorithm

8

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

slide-9
SLIDE 9

Graham Scan Algorithm

9

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

slide-10
SLIDE 10

Graham Scan Algorithm

10

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

slide-11
SLIDE 11

Graham Scan Algorithm

11

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

slide-12
SLIDE 12

Graham Scan Algorithm

12

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

slide-13
SLIDE 13

Graham Scan Algorithm

13

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

slide-14
SLIDE 14

Graham Scan Algorithm

14

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

slide-15
SLIDE 15

Graham Scan Algorithm

15

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

slide-16
SLIDE 16

Graham Scan Algorithm

16

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

slide-17
SLIDE 17

Graham Scan Algorithm

17

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

slide-18
SLIDE 18

Graham Scan Algorithm

18

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

slide-19
SLIDE 19

Graham Scan Algorithm

19

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

slide-20
SLIDE 20

Graham Scan Algorithm

20

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

slide-21
SLIDE 21

Graham Scan Algorithm

21

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

slide-22
SLIDE 22

Graham Scan Algorithm

22

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

slide-23
SLIDE 23

Graham Scan Algorithm

23

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

slide-24
SLIDE 24

Graham Scan Algorithm

24

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

slide-25
SLIDE 25

Graham Scan Algorithm

25

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

slide-26
SLIDE 26

Graham Scan Algorithm

26

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

slide-27
SLIDE 27

Graham Scan Algorithm

27

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

slide-28
SLIDE 28

Graham Scan Algorithm

28

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

slide-29
SLIDE 29

Graham Scan Algorithm

29

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

slide-30
SLIDE 30

Graham Scan Algorithm

30

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

slide-31
SLIDE 31

Graham Scan Algorithm

31

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

slide-32
SLIDE 32

Example

32

slide-33
SLIDE 33

Graham Scan Pseudo Code

Select the point with minimum 𝑧 Sort all points in CCW order π‘ž0, π‘ž1, … , π‘žπ‘œ 𝑇 = π‘ž0, π‘ž1 For 𝑗 = 2 to π‘œ

While |𝑇| > 2 && π‘žπ‘— is to the right of π‘‡βˆ’2, π‘‡βˆ’1

𝑇.pop

𝑇.push(π‘žπ‘—)

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)

34

slide-35
SLIDE 35

Example

35

slide-36
SLIDE 36

Pseudo Code

Sort 𝑇 by 𝑦 𝑉 = {𝑇0} For 𝑗 = 1 to π‘œ

while |𝑉| > 1 && 𝑇𝑗 is to the left of π‘‰βˆ’2π‘‰βˆ’1

𝑉.pop

𝑉.push(𝑇𝑗)

𝑀 = {𝑇0}

While |𝑀| > 1 && 𝑇𝑗 is to the right of π‘€βˆ’2π‘€βˆ’1

𝑀.pop

𝑀.push(𝑇𝑗)

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 Jarvi’s March Algorithm

37

slide-38
SLIDE 38

Gift Wrapping Example

38

slide-39
SLIDE 39

Gift Wrapping Example

39

slide-40
SLIDE 40

Gift Wrapping Example

40

slide-41
SLIDE 41

Gift Wrapping Example

41

slide-42
SLIDE 42

Gift Wrapping Example

42

slide-43
SLIDE 43

Gift Wrapping Example

43

slide-44
SLIDE 44

Gift Wrapping Example

44

slide-45
SLIDE 45

Gift Wrapping Example

45

slide-46
SLIDE 46

Gift Wrapping Example

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 𝑃(π‘œ β‹… 𝑙)

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)

48

slide-49
SLIDE 49

Divide & Conquer Convex Hull

ConvexHull(S)

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

49

 

slide-50
SLIDE 50

Merge: Upper Tangent

50

slide-51
SLIDE 51

Merge: Upper Tangent

51

slide-52
SLIDE 52

Merge: Upper Tangent

52

slide-53
SLIDE 53

Merge: Lower Tangent

53

slide-54
SLIDE 54

Merge: Lower Tangent

54

slide-55
SLIDE 55

Merge: Lower Tangent

55

slide-56
SLIDE 56

Merge: Lower Tangent

56

slide-57
SLIDE 57

Merge: Lower Tangent

57

slide-58
SLIDE 58

Merge: Lower Tangent

58

slide-59
SLIDE 59

Merge Step

Upper Tangent(𝑀, 𝑆)

𝑄𝑗 = Right most point in 𝑀 π‘„π‘˜ = Left most point in 𝑆 Do

Done = true While 𝑄

𝑗+1 is to the right of π‘žπ‘˜π‘žπ‘—

𝑗 + +; done = false

While 𝑄

π‘˜βˆ’1 is to the left of π‘žπ‘—π‘žπ‘˜

π‘˜ βˆ’ βˆ’; done = false

59

slide-60
SLIDE 60

Analysis

Sort step: 𝑃 π‘œ β‹… log π‘œ Merge step: 𝑃 π‘œ Recursive part

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

π‘œ 2 + 𝑑 β‹… π‘œ

π‘ˆ π‘œ = 𝑃 π‘œ β‹… log π‘œ

Overall running time 𝑃 π‘œ β‹… log π‘œ

60

slide-61
SLIDE 61

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

61

slide-62
SLIDE 62

Case 1: p inside CH

62

slide-63
SLIDE 63

Case 2: p on CH

63

slide-64
SLIDE 64

Case 3: p outside CH

64

slide-65
SLIDE 65

Case 3: p outside CH

65

slide-66
SLIDE 66

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)

66

slide-67
SLIDE 67

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

67

slide-68
SLIDE 68

Quick Hull

68

slide-69
SLIDE 69

Quick Hull

69

How to split the points across the line segment?

slide-70
SLIDE 70

Quick Hull

70

How to select the farthest point?

slide-71
SLIDE 71

Quick Hull

71

slide-72
SLIDE 72

Quick Hull

72

slide-73
SLIDE 73

Quick Hull

73

How to split the points into three subsets?

slide-74
SLIDE 74

Quick Hull

74

slide-75
SLIDE 75

Quick Hull

75

slide-76
SLIDE 76

Quick Hull

76

slide-77
SLIDE 77

Quick Hull

77

slide-78
SLIDE 78

Quick Hull

78

slide-79
SLIDE 79

Quick Hull

79

slide-80
SLIDE 80

Quick Hull

80

slide-81
SLIDE 81

Example

81

slide-82
SLIDE 82

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 π‘œ

82