CS133 Computational Geometry Intersection Problems 4/24/2018 1 - - PowerPoint PPT Presentation

β–Ά
cs133
SMART_READER_LITE
LIVE PREVIEW

CS133 Computational Geometry Intersection Problems 4/24/2018 1 - - PowerPoint PPT Presentation

CS133 Computational Geometry Intersection Problems 4/24/2018 1 Riddle: Fair Cake-cutting Using only one cut, how to split the cake into two equal pieces (by area)? Cake 4/24/2018 2 Riddle: Fair cake-cutting Cake with a hole! Still one


slide-1
SLIDE 1

CS133

Computational Geometry

Intersection Problems

4/24/2018 1

slide-2
SLIDE 2

Riddle: Fair Cake-cutting

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

4/24/2018 2

Cake

slide-3
SLIDE 3

Riddle: Fair cake-cutting

Cake with a hole! Still one cut

4/24/2018 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/24/2018 4

slide-5
SLIDE 5

Line Segment Intersection

4/24/2018 5

slide-6
SLIDE 6

Line Segment Intersection

4/24/2018 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?

4/24/2018 7

slide-8
SLIDE 8

Plane-sweep Algorithm

4/24/2018 8

slide-9
SLIDE 9

Plane-sweep Algorithm

4/24/2018 9

slide-10
SLIDE 10

Plane-sweep Algorithm

4/24/2018 10

slide-11
SLIDE 11

Plane-sweep Algorithm

4/24/2018 11

slide-12
SLIDE 12

Plane-sweep Algorithm

4/24/2018 12

slide-13
SLIDE 13

Plane-sweep Algorithm

4/24/2018 13

slide-14
SLIDE 14

Plane-sweep Algorithm

4/24/2018 14

slide-15
SLIDE 15

Plane-sweep Algorithm

4/24/2018 15

slide-16
SLIDE 16

Plane-sweep Algorithm

4/24/2018 16

slide-17
SLIDE 17

Plane-sweep Algorithm

4/24/2018 17

slide-18
SLIDE 18

Plane-sweep Algorithm

4/24/2018 18

slide-19
SLIDE 19

Plane-sweep Algorithm

4/24/2018 19

slide-20
SLIDE 20

Plane-sweep Algorithm

4/24/2018 20

slide-21
SLIDE 21

Plane-sweep Algorithm

4/24/2018 21

slide-22
SLIDE 22

Plane-sweep Algorithm

4/24/2018 22

slide-23
SLIDE 23

Plane-sweep Algorithm

4/24/2018 23

slide-24
SLIDE 24

Plane-sweep Algorithm

4/24/2018 24

slide-25
SLIDE 25

Plane-sweep Algorithm

4/24/2018 25

slide-26
SLIDE 26

Plane-sweep Simple Impl.

Input 𝑀 = π‘šπ‘— π‘šπ‘— = π‘šπ‘—. π‘ž1, π‘šπ‘—. π‘ž2 Prepare a sorted list of all y coordinates S={} For each stop with a corresponding line π‘šπ‘—

If top point

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

If end point

Remove π‘šπ‘— from S

4/24/2018 26

slide-27
SLIDE 27

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

4/26/2018 27

slide-28
SLIDE 28

Example

4/26/2018 28

Sweep line state (in sorted order)

slide-29
SLIDE 29

Algorithm Pseudo code

Create a list of event points P

P is always sorted by the y coordinate

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

p  P.pop processEvent(p)

4/26/2018 29

slide-30
SLIDE 30

Process Event Point (p)

If p is the top point Add p.l to S at the order p.x (p.l=Si) checkIntersection(Si-1, Si) checkIntersection(Si, Si+1) Add the end point of p.l to P If p is the bottom point Remove p.l from S (p.l=Si before removal) checkIntersection(Si-1,Si) If p is an interior point

Report p as an intersection Find p.l in S (p.l=Si) Swap(Si,Si+1) checkIntersection(Si-1, Si) checkIntersection(Si, Si+1)

4/26/2018 30

slide-31
SLIDE 31

Check Intersection(l1, l2)

If l1 does not intersect l2 then return Compute the intersection pi of l1 and l2 If pi.y is above the sweep line then return If π‘žπ‘— ∈ 𝑄 then return Insert pi into P

4/26/2018 31

slide-32
SLIDE 32

Analysis

Initial sort of starting points O(n log n) Number of processed event points (2n+k) For each event point

Remove from P: O(log |P|) Insert or remove from S: O(log |S|) Check intersection with at most two lines: O(1) Insert a new event points: O(log |P|)

Upper limit of |P| = 2n Upper limit of |S| = n Overall running time O((n+k)log n)

4/24/2018 32

slide-33
SLIDE 33

Corner Case 1: Horizontal Line

4/26/2018 33

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

slide-34
SLIDE 34

Corner Case 2: Three Intersecting Lines

4/26/2018 34

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-35
SLIDE 35

Rectangle Intersection

Given a set of rectangles, find all intersections

5/3/2018 35

slide-36
SLIDE 36

Example

5/3/2018 36

r1 r2 r3 r4

slide-37
SLIDE 37

Example

5/3/2018 37

r1 r2 r3 r4

slide-38
SLIDE 38

Rectangle Primitives

A 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))

5/3/2018 38

slide-39
SLIDE 39

NaΓ―ve Algorithm

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

5/3/2018 39

slide-40
SLIDE 40

Simple Plane-sweep Algo.

5/3/2018 40

r1 r2 r3 r4

slide-41
SLIDE 41

Simple Plane-sweep Algo.

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

5/3/2018 41

slide-42
SLIDE 42

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

5/3/2018 42

slide-43
SLIDE 43

Interval Tree Structure

5/3/2018 43

X-center

slide-44
SLIDE 44

A Simpler Interval Tree

Store the intervals in a BST ordered by i.xmin Augment the BST with the value xmax which stores the maximum value of all the intervals in the subtree

5/3/2018 44

slide-45
SLIDE 45

Augmented BST

5/3/2018 45

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

slide-46
SLIDE 46

Polygon Intersection

Given a set of polygons, find all intersecting polygons

5/3/2018 46

slide-47
SLIDE 47

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

5/3/2018 47

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

slide-48
SLIDE 48

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

5/3/2018 48

slide-49
SLIDE 49

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.

Polygon boundaries intersect

2.

Polygons are disjoint

3.

One polygon is contained in the other polygon

5/3/2018 49

slide-50
SLIDE 50

Test Case 1: 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

5/3/2018 50

slide-51
SLIDE 51

Computing the Intersection

5/3/2018 51

P Q

slide-52
SLIDE 52

Computing the Intersection

5/3/2018 52

P Q

slide-53
SLIDE 53

Computing the Intersection

5/3/2018 53

P Q

slide-54
SLIDE 54

Computing the Intersection

5/3/2018 54

P Q

slide-55
SLIDE 55

Computing the Intersection

5/3/2018 55

P Q

slide-56
SLIDE 56

Computing the Intersection

5/3/2018 56

P Q

slide-57
SLIDE 57

Computing the Intersection

5/3/2018 57

P Q

slide-58
SLIDE 58

Computing the Intersection

5/3/2018 58

P Q

slide-59
SLIDE 59

Computing the Intersection

5/3/2018 59

P Q

slide-60
SLIDE 60

Computing the Intersection

5/3/2018 60

P Q

slide-61
SLIDE 61

Computing the Intersection

5/3/2018 61

P Q

slide-62
SLIDE 62

Computing the Intersection

5/3/2018 62

P Q

slide-63
SLIDE 63

Computing the Intersection

5/3/2018 63

P Q

slide-64
SLIDE 64

Computing the Intersection

5/3/2018 64

P Q

slide-65
SLIDE 65

Case 2: Contained

5/3/2018 65

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-66
SLIDE 66

Case 3: Disjoint

5/3/2018 66

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

slide-67
SLIDE 67

Special Case: Convex Polygons

5/3/2018 67

P Q

slide-68
SLIDE 68

Convex Polygon Overlaps

5/3/2018 68

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

slide-69
SLIDE 69

Left-right Split

5/3/2018 69

slide-70
SLIDE 70

Left-right Overlap Test

5/3/2018 70

Compare the end point of

  • ne line segment to the
  • ther line segment using

Half space R L If the end point of R is to the right of the segment in L βž” Skip R. Why?

slide-71
SLIDE 71

Left-right Overlap Test

5/3/2018 71

Compare the end point of

  • ne line segment to the
  • ther line segment using

Half space R L Is the end point of R to the right of the segment in L? No! Do the line segments intersect? No! Switch to L Why?

slide-72
SLIDE 72

Left-right Overlap Test

5/3/2018 72

Compare the end point of

  • ne line segment to the
  • ther line segment using

Half space R L If the end point of L is to the left of the segment in R βž” Skip L

slide-73
SLIDE 73

Left-right Overlap Test

5/3/2018 73

Compare the end point of

  • ne line segment to the
  • ther line segment using

Half space R L Is the end point of L to the left of R? No! Do the line segments intersect? No! Switch to R

slide-74
SLIDE 74

Left-right Overlap Test

5/3/2018 74

Compare the end point of

  • ne line segment to the
  • ther line segment using

Half space R L Is the end point of R to the right of L? Yes! Skip R

slide-75
SLIDE 75

Left-right Overlap Test

5/3/2018 75

Compare the end point of

  • ne line segment to the
  • ther line segment using

Half space R L Is the end point of R to the right of L? No! Do the line segments intersect? Yes!

slide-76
SLIDE 76

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

5/3/2018 76