line segment intersection - kit...calculate all line segment intersections compute regions 3 dr....

68
Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection Tamara Mchedlidze · Darren Strash Computational Geometry · Lecture INSTITUT F ¨ UR THEORETISCHE INFORMATIK · FAKULT ¨ AT F ¨ UR INFORMATIK Line Segment Intersection 26.10.2015 1

Upload: others

Post on 11-Jul-2020

14 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Tamara Mchedlidze · Darren Strash

Computational Geometry · Lecture

INSTITUT FUR THEORETISCHE INFORMATIK · FAKULTAT FUR INFORMATIK

Line Segment Intersection

26.10.2015

1

Page 2: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Aside: Organizational Items

2

Page 3: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Overlaying Map Layers

+

=

Example: Given two different map layers whose intersection isof interest.

Land use

Precipitation

Map combining themes

3

Page 4: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Overlaying Map Layers

+

=

Example: Given two different map layers whose intersection isof interest.

Land use

Precipitation

Map combining themes

Regions are polygonsPolygons are line segmentsCalculate all line segment intersectionsCompute regions

3

Page 5: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Problem Formulation

Given: Set S = s1, . . . , sn of line segments in the plane

Output: all intersections of two or more line segmentsfor each intersection, the line segments involved.

4

Page 6: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Problem Formulation

Given: Set S = s1, . . . , sn of line segments in the plane

Output: all intersections of two or more line segmentsfor each intersection, the line segments involved.

Def: Line segments are closed

4

Page 7: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Problem Formulation

Given: Set S = s1, . . . , sn of line segments in the plane

Output: all intersections of two or more line segmentsfor each intersection, the line segments involved.

Def: Line segments are closed

Discussion:– How can you solve this problemnaively?– Is this already optimal?– Are their better approaches?

4

Page 8: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 9: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

Events

5

Page 10: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 11: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

sweep line

5

Page 12: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 13: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 14: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 15: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 16: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 17: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 18: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 19: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 20: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 21: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 22: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 23: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 24: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 25: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 26: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 27: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 28: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 29: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

The Sweep-Line Method: An Example

5

Page 30: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Data Structures

1.) Event Queue Qdefine p ≺ q ⇔def. yp > yq ∨ (yp = yq ∧ xp < xq)

p q`

6

Page 31: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Data Structures

1.) Event Queue Qdefine p ≺ q ⇔def. yp > yq ∨ (yp = yq ∧ xp < xq)

p q`

Store events by ≺ in a balanced binary search tree

→ e.g., AVL tree, red-black tree, . . .

6

Page 32: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Data Structures

1.) Event Queue Qdefine p ≺ q ⇔def. yp > yq ∨ (yp = yq ∧ xp < xq)

p q`

Store events by ≺ in a balanced binary search tree

→ e.g., AVL tree, red-black tree, . . .

Operations insert, delete and nextEvent in O(log |Q|) time

6

Page 33: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Data Structures

1.) Event Queue Qdefine p ≺ q ⇔def. yp > yq ∨ (yp = yq ∧ xp < xq)

p q`

Store events by ≺ in a balanced binary search tree

→ e.g., AVL tree, red-black tree, . . .

Operations insert, delete and nextEvent in O(log |Q|) time

2.) Sweep-Line Status T `

Stores ` cut lines ordered from left to right

6

Page 34: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Data Structures

1.) Event Queue Qdefine p ≺ q ⇔def. yp > yq ∨ (yp = yq ∧ xp < xq)

p q`

Store events by ≺ in a balanced binary search tree

→ e.g., AVL tree, red-black tree, . . .

Operations insert, delete and nextEvent in O(log |Q|) time

2.) Sweep-Line Status T `

Stores ` cut lines ordered from left to right

Required operations insert, delete, findNeighbor

6

Page 35: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Data Structures

1.) Event Queue Qdefine p ≺ q ⇔def. yp > yq ∨ (yp = yq ∧ xp < xq)

p q`

Store events by ≺ in a balanced binary search tree

→ e.g., AVL tree, red-black tree, . . .

Operations insert, delete and nextEvent in O(log |Q|) time

2.) Sweep-Line Status T `

Stores ` cut lines ordered from left to right

Required operations insert, delete, findNeighbor

This is also a balanced binary search tree with line segments stored inthe leaves!

6

Page 36: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Algorithm

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersection points and the line segments

involvedQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

7

Page 37: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Algorithm

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersection points and the line segments

involvedQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

What happenswith duplicates?

7

Page 38: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Algorithm

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersection points and the line segments

involvedQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

What happenswith duplicates?

This is the core of thealgorithm!

7

Page 39: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Algorithm

handleEvent(p)

U(p)← Line segments with p as upper endpointL(p)← Line segments with p as lower endpointC(p)← Line segments with p as interior pointif |U(p) ∪ L(p) ∪ C(p)| ≥ 2 then

return p and U(p) ∪ L(p) ∪ C(p)

remove L(p) ∪ C(p) from Tadd U(p) ∪ C(p) to Tif U(p) ∪ C(p) = ∅ then //sl and sr, neighbors of p in TQ ← check if sl and sr intersect below p

else //s′ and s′′ leftmost and rightmost line segment in U(p) ∪ C(p)Q ← check if sl and s′ intersect below pQ ← check if sr and s′′ intersect below p

8

Page 40: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Algorithm

handleEvent(p)

U(p)← Line segments with p as upper endpointL(p)← Line segments with p as lower endpointC(p)← Line segments with p as interior pointif |U(p) ∪ L(p) ∪ C(p)| ≥ 2 then

return p and U(p) ∪ L(p) ∪ C(p)

remove L(p) ∪ C(p) from Tadd U(p) ∪ C(p) to Tif U(p) ∪ C(p) = ∅ then //sl and sr, neighbors of p in TQ ← check if sl and sr intersect below p

else //s′ and s′′ leftmost and rightmost line segment in U(p) ∪ C(p)Q ← check if sl and s′ intersect below pQ ← check if sr and s′′ intersect below p

Stored with p in Q

8

Page 41: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Algorithm

handleEvent(p)

U(p)← Line segments with p as upper endpointL(p)← Line segments with p as lower endpointC(p)← Line segments with p as interior pointif |U(p) ∪ L(p) ∪ C(p)| ≥ 2 then

return p and U(p) ∪ L(p) ∪ C(p)

remove L(p) ∪ C(p) from Tadd U(p) ∪ C(p) to Tif U(p) ∪ C(p) = ∅ then //sl and sr, neighbors of p in TQ ← check if sl and sr intersect below p

else //s′ and s′′ leftmost and rightmost line segment in U(p) ∪ C(p)Q ← check if sl and s′ intersect below pQ ← check if sr and s′′ intersect below p

Stored with p in Q

Neighbors in T

8

Page 42: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Algorithm

handleEvent(p)

U(p)← Line segments with p as upper endpointL(p)← Line segments with p as lower endpointC(p)← Line segments with p as interior pointif |U(p) ∪ L(p) ∪ C(p)| ≥ 2 then

return p and U(p) ∪ L(p) ∪ C(p)

remove L(p) ∪ C(p) from Tadd U(p) ∪ C(p) to Tif U(p) ∪ C(p) = ∅ then //sl and sr, neighbors of p in TQ ← check if sl and sr intersect below p

else //s′ and s′′ leftmost and rightmost line segment in U(p) ∪ C(p)Q ← check if sl and s′ intersect below pQ ← check if sr and s′′ intersect below p

Stored with p in Q

Neighbors in T

Remove and insertreverses order in C(p)

8

Page 43: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

What Happens Exactly?

s1

s2

s3

s4

s5s6

s7 s6 s5 s4 s1

s3 s7

s1

s5

s6 s4

s3

T

p

S

9

Page 44: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

What Happens Exactly?

s1

s2

s3

s4

s5s6

s7 s6 s5 s4 s1

s3 s7

s1

s5

s6 s4

s3

T

p

U(p) = s2L(p) =C(p) =

S

9

Page 45: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

What Happens Exactly?

s1

s2

s3

s4

s5s6

s7 s6 s5 s4 s1

s3 s7

s1

s5

s6 s4

s3

T

p

U(p) = s2L(p) =C(p) =

S

9

Page 46: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

What Happens Exactly?

s1

s2

s3

s4

s5s6

s7 s6 s5 s4 s1

s3 s7

s1

s5

s6 s4

s3

T

p

U(p) = s2L(p) = s4, s5C(p) = s1, s3

S

9

Page 47: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

What Happens Exactly?

s1

s2

s3

s4

s5s6

s7 s6 s5 s4 s1

s3 s7

s1

s5

s6 s4

s3

T

p

U(p) = s2L(p) = s4, s5C(p) = s1, s3

Report (p, s1, s2, s3, s4, s5)

S

9

Page 48: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

What Happens Exactly?

s1

s2

s3

s4

s5s6

s7 s6 s5 s4 s1

s3 s7

s1

s5

s6 s4

s3

T

p

U(p) = s2L(p) = s4, s5C(p) = s1, s3 s6

s7

s2

s3

s6

s1

s3

s2 s1

Delete L(p) ∪ C(p); add U(p) ∪ C(p)

S

9

Page 49: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

What Happens Exactly?

s1

s2

s3

s4

s5s6

s7 s6 s5 s4 s1

s3 s7

s1

s5

s6 s4

s3

T

p

U(p) = s2L(p) = s4, s5C(p) = s1, s3 s6

s7

s2

s3

s6

s1

s3

s2 s1

Add event p′ = s1 × s7 in Q s′

s′′ sr

sl

p′

S

9

Page 50: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Correctness

Lemma 1:Algorithm FindIntersections finds all intersectionpoints and the line segments involved

10

Page 51: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Correctness

Lemma 1:Algorithm FindIntersections finds all intersectionpoints and the line segments involved

Proof:Induction on the number of events processed.

Let p be an intersection point and all intersection points q ≺ pare already correctly computed.

Case 1: p is a line segment endpointp was inserted in QU(p) stores pL(p) and C(p) are in T

10

Page 52: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Correctness

Lemma 1:Algorithm FindIntersections finds all intersectionpoints and the line segments involved

Proof:Induction on the number of events processed.

Let p be an intersection point and all intersection points q ≺ pare already correctly computed.

Case 1: p is a line segment endpointp was inserted in QU(p) stores pL(p) and C(p) are in T

Case 2: p is not a line segment endpoint

Consider why p must be in Q!10

Page 53: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Running-Time Analysis

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersections with their line segmentsQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

11

Page 54: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Running-Time Analysis

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersections with their line segmentsQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

O(1)

11

Page 55: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Running-Time Analysis

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersections with their line segmentsQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

O(1)

O(n log n)

11

Page 56: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Running-Time Analysis

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersections with their line segmentsQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

O(1)

O(n log n)

O(log |Q|)

11

Page 57: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Running-Time Analysis

FindIntersections(S)

Input: Set S of line segmentsOutput: Set of all intersections with their line segmentsQ ← ∅; T ← ∅foreach s ∈ S doQ.insert(upperEndPoint(s))Q.insert(lowerEndPoint(s))

while Q 6= ∅ dop← Q.nextEvent()Q.deleteEvent(p)handleEvent(p)

O(1)

O(n log n)

O(log |Q|) ?

11

Page 58: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Running-Time Analysis

Lemma 2:Algorithm FindIntersections has running timeO(n log n + I log n), where I is the number ofintersection points.

handleEvent(p)

U(p)← Line segments with p as upper endpointL(p)← Line segments with p as lower endpointC(p)← Line segments with p as interior pointif |U(p) ∪ L(p) ∪ C(p)| ≥ 2 then

return p and U(p) ∪ L(p) ∪ C(p)

remove L(p) ∪ C(p) from Tadd U(p) ∪ C(p) to Tif U(p) ∪ C(p) = ∅ then //sl and sr, neighbors of p in TQ ← check if sl and sr intersect below p

else //s′ and s′′ leftmost and rightmost line segment in U(p) ∪ C(p)Q ← check if sl and s′ intersect below pQ ← check if sr and s′′ intersect below p

12

Page 59: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Summary

Thm 1:Let S be a set of n line segments in the plane. Thenwe can compute intersections in S together with theinvolved line segments in O((n + I) log n) time andO(?) space.

13

Page 60: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Summary

Thm 1:Let S be a set of n line segments in the plane. Thenwe can compute intersections in S together with theinvolved line segments in O((n + I) log n) time andO(?) space.

Proof:Correctness XRunning time XSpace

13

Page 61: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Summary

Thm 1:Let S be a set of n line segments in the plane. Thenwe can compute intersections in S together with theinvolved line segments in O((n + I) log n) time andO(?) space.

Proof:Correctness XRunning time XSpace

Consider how much space thedata structures need!

13

Page 62: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Summary

Proof:Correctness XRunning time XSpace

– T has at most n elements– Q has at most O(n + I) elements– reduction of Q to O(n) space: an exercise

Consider how much space thedata structures need!

Thm 1:Let S be a set of n line segments in the plane. Thenwe can compute intersections in S together with theinvolved line segments in O((n + I) log n) time andO(n) space.

13

Page 63: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Discussion

Is the Sweep-Line Algorithm always better than the naive one?

14

Page 64: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Discussion

Is the Sweep-Line Algorithm always better than the naive one?

No, because if I ∈ Ω(n2) then the algorithm has running timeO(n2 log n).

14

Page 65: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Discussion

Is the Sweep-Line Algorithm always better than the naive one?

No, because if I ∈ Ω(n2) then the algorithm has running timeO(n2 log n).

Can we do better?

14

Page 66: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Discussion

Is the Sweep-Line Algorithm always better than the naive one?

No, because if I ∈ Ω(n2) then the algorithm has running timeO(n2 log n).

Can we do better?

Yes, in Θ(n log n + I) time and Θ(n) space [Balaban, 1995].

14

Page 67: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Discussion

Is the Sweep-Line Algorithm always better than the naive one?

No, because if I ∈ Ω(n2) then the algorithm has running timeO(n2 log n).

Can we do better?

Yes, in Θ(n log n + I) time and Θ(n) space [Balaban, 1995].

How does this solve the map overlay problem?

14

Page 68: Line Segment Intersection - KIT...Calculate all line segment intersections Compute regions 3 Dr. Tamara Mchedlidze Dr. Darren Strash Computational Geometry Lecture Line Segment Intersection

Dr. Tamara Mchedlidze · Dr. Darren Strash · Computational Geometry Lecture Line Segment Intersection

Discussion

Is the Sweep-Line Algorithm always better than the naive one?

No, because if I ∈ Ω(n2) then the algorithm has running timeO(n2 log n).

Can we do better?

Yes, in Θ(n log n + I) time and Θ(n) space [Balaban, 1995].

How does this solve the map overlay problem?

Using an appropriate data structure (doubly-connected edgelist) forplanar graphs we can compute in O((n + I) log n) time the overlay oftwo maps.(Details in Ch. 2.3 of the book)

14