CS133 Computational Geometry Intersection Problems 1 Riddle: Fair - - PowerPoint PPT Presentation

β–Ά
cs133
SMART_READER_LITE
LIVE PREVIEW

CS133 Computational Geometry Intersection Problems 1 Riddle: Fair - - PowerPoint PPT Presentation

CS133 Computational Geometry Intersection Problems 1 Riddle: Fair Cake-cutting Using only one straight-line cut, how to split the cake into two equal pieces (by area)? Cake 2 Riddle: Fair cake-cutting Mixed cake! Still one cut Cake Cake


slide-1
SLIDE 1

CS133

Computational Geometry

Intersection Problems

1

slide-2
SLIDE 2

Riddle: Fair Cake-cutting

Using only one straight-line cut, how to split the cake into two equal pieces (by area)?

2

Cake

slide-3
SLIDE 3

Riddle: Fair cake-cutting

Mixed cake! Still one cut

3

Cake Cake

slide-4
SLIDE 4

Line Segment Intersections

Given a set of line segments, each defined by two end points, find all intersecting line segments

4

slide-5
SLIDE 5

Line Segment Intersection

5

slide-6
SLIDE 6

Line Segment Intersection

6

slide-7
SLIDE 7

NaΓ―ve Algorithm

Enumerate all possible pairs of lines Test for intersection Running time O(n2) What is the lower bound of the running time? Worst case: O(n2) Is this optimal?

7

slide-8
SLIDE 8

Plane-sweep Algorithm

8

slide-9
SLIDE 9

Plane-sweep Algorithm

9

slide-10
SLIDE 10

Plane-sweep Algorithm

10

slide-11
SLIDE 11

Plane-sweep Algorithm

11

slide-12
SLIDE 12

Plane-sweep Algorithm

12

slide-13
SLIDE 13

Plane-sweep Algorithm

13

slide-14
SLIDE 14

Plane-sweep Algorithm

14

slide-15
SLIDE 15

Plane-sweep Algorithm

15

slide-16
SLIDE 16

Plane-sweep Algorithm

16

slide-17
SLIDE 17

Plane-sweep Algorithm

17

slide-18
SLIDE 18

Plane-sweep Algorithm

18

slide-19
SLIDE 19

Plane-sweep Algorithm

19

slide-20
SLIDE 20

Plane-sweep Algorithm

20

slide-21
SLIDE 21

Plane-sweep Algorithm

21

slide-22
SLIDE 22

Plane-sweep Algorithm

22

slide-23
SLIDE 23

Plane-sweep Algorithm

23

slide-24
SLIDE 24

Plane-sweep Algorithm

24

slide-25
SLIDE 25

Plane-sweep Algorithm

25

slide-26
SLIDE 26

Elements of Plane-sweep

The sweep line: Sweeps the plane in specific direction, e.g., top-down The state of the sweep line 𝑇: A set of all line segments that intersect the sweep line at any

  • position. The state changes as the line move.

The event points 𝐹: Is the set of points where the state 𝑇 changes. In this case, the end points of the line segments comprise the event points.

26

slide-27
SLIDE 27

Example: Event Points

27

π‘š1 π‘š2 π‘š3

(4,10) (1,7) (2,5) (3,5) (5,6) (3,3) 𝒛 π’Žπ’‹ Start/End 10 π‘š1 Start 7 π‘š2 Start 6 π‘š3 Start 5 π‘š1 End 5 π‘š2 End 3 π‘š3 End

slide-28
SLIDE 28

Plane-sweep Simple Impl.

Input 𝑀 = π‘šπ‘— π‘šπ‘— = π‘šπ‘—. π‘ž1, π‘šπ‘—. π‘ž2 𝐹= the list of 𝑧-coordinates sorted in decreasing

  • rder

𝑇 = {} For each event with a corresponding line π‘šπ‘—

If top point

Compare π‘šπ‘— to each 𝑑 ∈ 𝑇 Insert π‘šπ‘— to S

If end point

Remove π‘šπ‘— from S

28

slide-29
SLIDE 29

Plane-sweep Poor Behavior

29

𝑃 π‘œ2

slide-30
SLIDE 30

Bentley-Ottmann Algorithm

An improved scan-line algorithm Maintains the state S in a sorted order to speed up checking a line segment against segments in S

30

slide-31
SLIDE 31

Example

31

Sweep line state (in sorted order)

slide-32
SLIDE 32

Algorithm Pseudo code

Create a list of event points 𝑄

𝑄 is always sorted by the 𝑧 coordinate

Initialize the state 𝑇 to an empty list Initialize 𝑄 with the first point (top point) of each line segment While 𝑄 is not empty

π‘ž  𝑄.pop 𝑧𝑑 = π‘ž. 𝑧 processEvent(π‘ž)

32

slide-33
SLIDE 33

Process Event Point (p)

// p is the top (starting) point If π‘ž is the top point Add π‘ž. π‘š to 𝑇 at the order π‘ž. 𝑦 (π‘ž. π‘š = 𝑇𝑗) checkIntersection(π‘‡π‘—βˆ’1, 𝑇𝑗) checkIntersection(𝑇𝑗, 𝑇𝑗+1) Add the end point of π‘ž. π‘š to 𝑄

33

slide-34
SLIDE 34

Process Event Point (p)

// p is the bottom (ending) point If π‘ž is the bottom point // let π‘ž. π‘š be at position 𝑇𝑗 before removal Remove π‘ž. π‘š from 𝑇 checkIntersection(π‘‡π‘—βˆ’1, 𝑇𝑗)

34

slide-35
SLIDE 35

Process Event Point (p)

If π‘ž is an interior point

Report π‘ž as an intersection Find π‘ž. π‘š in 𝑇 (π‘ž. π‘š = 𝑇𝑗, 𝑇𝑗+1 ) Swap(𝑇𝑗, 𝑇𝑗+1) checkIntersection(π‘‡π‘—βˆ’1, 𝑇𝑗) checkIntersection(𝑇𝑗+1, 𝑇𝑗+2)

35

slide-36
SLIDE 36

Check Intersection(π‘š1, π‘š2)

If π‘š1 does not intersect π‘š2 then return Compute the intersection π‘žπ‘— of π‘š1 and π‘š2 If π‘žπ‘—. 𝑧 is above the sweep line then return If π‘žπ‘— ∈ 𝑄 then return Insert π‘žπ‘— into 𝑄

36

slide-37
SLIDE 37

Sweep Line State (𝑇)

A list of line segments [π‘šπ‘—] Sorted by the 𝑦-coordinate of the intersections between π‘šπ‘— and the sweep line

37

π‘šπ‘—[0] π‘šπ‘—[1]

𝑧𝑑

π‘šπ‘— 0 . 𝑦 + Δ𝑦 Δ𝑧 𝑧𝑑 βˆ’ π‘šπ‘— 0 . 𝑧 , 𝑧𝑑 Δ𝑦 Δ𝑧

slide-38
SLIDE 38

Analysis

Initial sort of starting points 𝑃 π‘œ β‹… log π‘œ Number of processed event points 2π‘œ + 𝑙 For each event point

Remove from P: 𝑃 log 𝑄 Insert or remove from S: 𝑃 log 𝑇 Check intersection with at most two lines: 𝑃 1 Insert a new event points: 𝑃 log 𝑄

Upper limit of 𝑄 = 2π‘œ Upper limit of 𝑇 = π‘œ Overall running time 𝑃 π‘œ + 𝑙 log π‘œ

38

slide-39
SLIDE 39

Corner Case 1: Horizontal Line

39

l1 l2 l3 If two points have the same y-coordinate, sort them by the x-coordinate Starting point

slide-40
SLIDE 40

Corner Case 2: Three Intersecting Lines

40

l1 l2 l3 Allow the event point to store a list of all intersecting line segments When processed, reverse the

  • rder of all the lines
slide-41
SLIDE 41

Rectangle Intersection

Given a set of orthogonal rectangles (𝑆), find the set of all intersections between pairs of rectangles 𝑠

1 ∩ 𝑠2: 𝑠 1, 𝑠2 ∈ 𝑆

41

slide-42
SLIDE 42

Example

42

r1 r2 r3 r4

slide-43
SLIDE 43

Example

43

r1 r2 r3 r4

slide-44
SLIDE 44

Rectangle Primitives

An orthogonal rectangle is represented by its two corner points, lower and upper Test if two rectangles overlap

Two rectangles overlap if both their x intervals and y-intervals overlap Intervals overlap [x1,x2], [x3,x4]: x4>=x1 and x2>=x3

R1(x1,y1,x2,y2)Γ—R2(x3,y3,x4,y4) βž” R3(Max(x1,x3), Max(y1,y3), Min(x2,x4), Min(y2,y4))

44

slide-45
SLIDE 45

NaΓ―ve Algorithm

Test all pairs of rectangles and report the intersections Running time O(n2) Is it optimal?

45

slide-46
SLIDE 46

Simple Plane-sweep Algo.

46

r1 r2 r3 r4

slide-47
SLIDE 47

Simple Plane-sweep Algo.

What is the state of the sweep line? What is an event? What processing should be done at each event?

47

slide-48
SLIDE 48

Improved Plane-sweep Algo.

Keep the sweep line state sorted

But how?

Interval tree A variation of BST Stores intervals Supports two operation

Find all intervals that overlap a query point π‘ž Find all intervals that overlap a query interval π‘Ÿ

48

slide-49
SLIDE 49

A Simple Interval Tree

Store the intervals in a BST ordered by 𝑗. π‘¦π‘›π‘—π‘œ Augment the BST with the value 𝑦𝑛𝑏𝑦 which stores the maximum value of all the intervals in the subtree

50

slide-50
SLIDE 50

Augmented BST

51

Credit: https://en.wikipedia.org/wiki/Interval_tree

slide-51
SLIDE 51

Polygon Intersection

Given a set of polygons, find all intersecting polygons

52

slide-52
SLIDE 52

Polygon Representation

A polygon is represented as a sequence of points that form its boundary A general polygon might also contain holes, e.g., a grass area with a lake inside For simplicity, we will only deal with solid polygons with no holes

53

p1 p2 p3 p4 p5 p6 p7 p8 Corners Edge or Segment

slide-53
SLIDE 53

Filter-and-refine Approach

Convert all polygons to rectangles

For each polygon, compute its minimum bounding rectangle (MBR)

Filter: Find all overlapping rectangles Refine: Test the polygons that have

  • verlapping MBBs

54

slide-54
SLIDE 54

Filter-and-refine Approach

Filter step: Already studied Refine: How to find the intersection of two polygons? For any two polygons, there are three cases:

1.

Polygons are disjoint

2.

One polygon is contained in the other polygon

3.

Polygon boundaries intersect

55

slide-55
SLIDE 55

Case 1: Disjoint

56

P Q No intersection points Neither 𝑄 βŠ‚ 𝑅 nor 𝑅 βŠ‚ 𝑄 The intersection is empty

slide-56
SLIDE 56

Case 2: Contained

57

P Q No intersection points If 𝑄 βŠ‚ 𝑅, then any corner

  • f P is ∈ 𝑅

If 𝑅 βŠ‚ 𝑄, then any corner

  • f Q is ∈ 𝑄

The intersection is the contained polygon

slide-57
SLIDE 57

Case 3: Intersecting

If the boundaries of the two polygons overlap, then there is at least two polygon edges that

  • verlap

NaΓ―ve solution: Compute all intersections between every pair of edges 𝑃 𝑛 β‹… π‘œ

Where 𝑛 and π‘œ are the sizes of the two polygons

We can also use the line-segment sweep-line algorithm

Run in 𝑃 𝑙 + 𝐽 log 𝑙 where 𝑙 = 𝑛 + π‘œ and 𝐽 is the number of intersections If we only need to test, we can stop at the first intersection

58

slide-58
SLIDE 58

Computing the Intersection

59

P Q

slide-59
SLIDE 59

Computing the Intersection

60

P Q

slide-60
SLIDE 60

Computing the Intersection

61

P Q

slide-61
SLIDE 61

Computing the Intersection

62

P Q

slide-62
SLIDE 62

Computing the Intersection

63

P Q

slide-63
SLIDE 63

Computing the Intersection

64

P Q

slide-64
SLIDE 64

Computing the Intersection

65

P Q

slide-65
SLIDE 65

Computing the Intersection

66

P Q

slide-66
SLIDE 66

Computing the Intersection

67

P Q

slide-67
SLIDE 67

Computing the Intersection

68

P Q

slide-68
SLIDE 68

Computing the Intersection

69

P Q

slide-69
SLIDE 69

Computing the Intersection

70

P Q

slide-70
SLIDE 70

Computing the Intersection

71

P Q

slide-71
SLIDE 71

Computing the Intersection

72

P Q

slide-72
SLIDE 72

Special Case: Convex Polygons

73

P Q

slide-73
SLIDE 73

Convex Polygon Overlaps

74

Right-left Right-right left-left Left-right

slide-74
SLIDE 74

Left-right Split

75

slide-75
SLIDE 75

Left-right Overlap Test

76

Observation: the points of each half are monotone along the 𝑧-axis

R L

Since the segments that form each hull are monotone (i.e., going down), there is no chance for the top red segment to intersect the green half-hull Start with the top two segments from each half-hull Do they intersect? No!

slide-76
SLIDE 76

Left-right Overlap Test

77

The bottom point of the green segment is higher than all remaining red segments

R L

Skip to the next green line segment Do the current segments intersect? No!

slide-77
SLIDE 77

Left-right Overlap Test

78

R L

The bottom point of the red segment is higher. Skip to the next. Do the current segments intersect? No!

slide-78
SLIDE 78

Left-right Overlap Test

79

Report the intersection

R L

Bottom green point is higher. Skip to the next green segment. Do the current segments intersect? Yes!

slide-79
SLIDE 79

Left-right Overlap Test

80

R L

Report the intersection Do the current segments intersect? Yes! Bottom red point is higher. Skip to the next red segment.

slide-80
SLIDE 80

Left-right Overlap Test

81

R L

Do the current segments intersect? No! Both bottom points are at equal 𝑧-coordinate. Skip any of them

slide-81
SLIDE 81

Right-right Overlap Test

82

slide-82
SLIDE 82

Right-right Overlap Test

83

slide-83
SLIDE 83

Right-right Overlap Test

84

slide-84
SLIDE 84

Right-right Overlap Test

85

slide-85
SLIDE 85

Right-right Overlap Test

86

slide-86
SLIDE 86

Right-right Overlap Test

87

slide-87
SLIDE 87

Convex Polygon Intersection

If only testing is required, the algorithm can terminate as soon as the first intersection is found If the polygon intersection is needed, the algorithm reports all intersections The algorithm terminates when all segments are inspected Running time: 𝑃 𝑛 + π‘œ , each iteration skips

  • ne segment

88