# Line-Segment Intersection Map Overlay by dfgh4bnmu

VIEWS: 43 PAGES: 60

• pg 1
```									                   Chapter 2

Line-Segment Intersection
or:
Map Overlay

Alexander Wolﬀ    TU/e     Geometric Algorithms (2IL55)
Line-Segment Intersection
Application ?
Line-Segment Intersection
Application: map overlay (GIS)
Line-Segment Intersection
Application: map overlay (GIS)

Deﬁnition:
Line-Segment Intersection
Application: map overlay (GIS)

Deﬁnition:   Is            an intersection?
Line-Segment Intersection
Application: map overlay (GIS)

Deﬁnition:   Is             an intersection?

Line-Segment Intersection
Application: map overlay (GIS)

Deﬁnition:   Is              an intersection?

Problem:     Given a set S of n closed non-overlapping line
segments in the plane, compute:
– all points where at least two segments intersect
and
– for each such point report all segments
that contain it.
Line-Segment Intersection
Application: map overlay (GIS)

Deﬁnition:   Is              an intersection?

Problem:     Given a set S of n closed non-overlapping line
segments in the plane, compute:
– all points where at least two segments intersect
and
– for each such point report all segments
that contain it.
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq   or   (yp = yq and xp < xq )
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq   or   (yp = yq and xp < xq )
p                    q
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq   or   (yp = yq and xp < xq )
p                    q
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq   or   (yp = yq and xp < xq )
p                    q
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq    or   (yp = yq and xp < xq )
p                        q

Store event pts in balanced binary search tree acc. to
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq    or   (yp = yq and xp < xq )
p                        q

Store event pts in balanced binary search tree acc. to
⇒ nextEvent() and del/insEvent() take O(log |Q|) time
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq    or   (yp = yq and xp < xq )
p                        q

Store event pts in balanced binary search tree acc. to
⇒ nextEvent() and del/insEvent() take O(log |Q|) time

2) (sweep-line) status T
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq    or   (yp = yq and xp < xq )
p                        q

Store event pts in balanced binary search tree acc. to
⇒ nextEvent() and del/insEvent() take O(log |Q|) time

2) (sweep-line) status T
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq    or   (yp = yq and xp < xq )
p                        q

Store event pts in balanced binary search tree acc. to
⇒ nextEvent() and del/insEvent() take O(log |Q|) time

2) (sweep-line) status T
Store the segments intersected by   in left-to-right order.
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq    or   (yp = yq and xp < xq )
p                        q

Store event pts in balanced binary search tree acc. to
⇒ nextEvent() and del/insEvent() take O(log |Q|) time

2) (sweep-line) status T
Store the segments intersected by   in left-to-right order.
How?
Data structures for a top-to-bottom sweep
1) event (-point) queue Q
p   q   ⇔def.   yp > yq    or   (yp = yq and xp < xq )
p                        q

Store event pts in balanced binary search tree acc. to
⇒ nextEvent() and del/insEvent() take O(log |Q|) time

2) (sweep-line) status T
Store the segments intersected by   in left-to-right order.
How?    In a balanced binary search tree!
Sweep-line algorithm
ﬁndIntersections(S)
Input:    set S of n non-overlapping closed line segments
Output: set I of intersection pts
for each p ∈ I every s ∈ S with p ∈ s
Sweep-line algorithm
ﬁndIntersections(S)
Input:    set S of n non-overlapping closed line segments
Output: set I of intersection pts
for each p ∈ I every s ∈ S with p ∈ s
Q ← ∅; T ← ∅
foreach s ∈ S do
Q.insert(upperEndPt(s))
Q.insert(lowerEndPt(s))
Sweep-line algorithm
ﬁndIntersections(S)
Input:    set S of n non-overlapping closed line segments
Output: set I of intersection pts
for each p ∈ I every s ∈ S with p ∈ s
Q ← ∅; T ← ∅
foreach s ∈ S do
Q.insert(upperEndPt(s))
Q.insert(lowerEndPt(s))

while Q = ∅ do
p ← Q.nextEvent()
Q.deleteEvent(p)
handleEvent(p)
Correctness and running time
Lemma:   ﬁndIntersections() correctly computes all inter-
section points & the segments that contain them.
Correctness and running time
Lemma:   ﬁndIntersections() correctly computes all inter-
section points & the segments that contain them.

Lemma:   ﬁndIntersections() ﬁnds I intersection points
among n non-overlapping line segments in
O((n + I) log n) time.
Correctness and running time
Lemma:     ﬁndIntersections() correctly computes all inter-
section points & the segments that contain them.

Lemma:     ﬁndIntersections() ﬁnds I intersection points
among n non-overlapping line segments in
O((n + I) log n) time.

Theorem: We can report all I intersection points among n
non-overlapping line segments in the plane and
report the segments involved in the intersections in
O((n + I) log n) time and O(n) space.
Doubly-Connected Edge List
Motivation:   – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

graph
nodes
arcs
abstract
information
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

graph               subdivision
nodes               vertices
arcs                edges
abstract
information
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

graph               subdivision           geometry
nodes               vertices              points in R2
arcs                edges                 line segments
(or: circular arcs...)
abstract
information
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

graph                      subdivision    geometry
nodes                      vertices       points in R2
incident

arcs                       edges          line segments
(or: circular arcs...)
abstract
information
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

graph                      subdivision             geometry
nodes                      vertices                points in R2
incident

arcs                       edges                   line segments
(or: circular arcs...)
abstract
information                       maximal connected subsets of the plane
without vertices and edges
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

graph                      subdivision             geometry
nodes                      vertices                points in R2

incident

arcs                       edges                   line segments
(or: circular arcs...)
abstract
information                       maximal connected subsets of the plane
without vertices and edges
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

gy
graph                      subdivision                 geometry

lo
po
to
nodes                      vertices                    points in R2

incident

arcs                       edges                       line segments
(or: circular arcs...)
abstract
information                       maximal connected subsets of the plane
without vertices and edges
Doubly-Connected Edge List
Motivation:    – data structure for planar subdivisions
– map overlay (e.g., rivers and streets)
– “walk” on the map, from region to region

gy
graph                      subdivision                 geometry

lo
po
to
nodes                      vertices                    points in R2

incident

arcs                       edges                       line segments
(or: circular arcs...)
abstract
information                       maximal connected subsets of the plane
without vertices and edges

complexity of a subdiv. := #vertices + #edges + #faces
DCEL: Notation and an Example
twin(e)
origin(e)
e
next(e)
prev(e)
face(e)
DCEL: Notation and an Example
twin(e)                 Note: Half-edges are oriented
origin(e)       such that incident face
e                         lies locally to the left.
next(e)
prev(e)
face(e)
DCEL: Notation and an Example
twin(e)                    Note: Half-edges are oriented
origin(e)       such that incident face
e                           lies locally to the left.
next(e)
prev(e)
face(e)

v1          e11        v2
f2
e21
e41

f1                     v3
e32
v4         e31
DCEL: Notation and an Example
twin(e)                    Note: Half-edges are oriented
origin(e)       such that incident face
e                           lies locally to the left.
next(e)
prev(e)
face(e)

v1          e11        v2
f2
e21     edge   origin   twin   face   next   prev
e41
e11     v1      e22    f1     e21   e41
f1                     v3        e12     v2      e11    f2     e42   e22
e32
e21     v2      e22    f1     e31   e11
v4         e31
...
DCEL: Notation and an Example
twin(e)                         vertex   coordinates   edge
origin(e)        v1        (0, 3)      e11
e                            v2        (2, 3)      e21
next(e)                                   v3        (2, 1)      e31
prev(e)
v4        (1, 0)      e22
face(e)

v1          e11        v2
f2
e21     edge      origin   twin   face   next   prev
e41
e11        v1      e22    f1     e21   e41
f1                     v3        e12        v2      e11    f2     e42   e22
e32
e21        v2      e22    f1     e31   e11
v4         e31
...
DCEL: Notation and an Example
twin(e)                         vertex   coordinates   edge
origin(e)        v1        (0, 3)      e11
e                            v2        (2, 3)      e21
next(e)                                   v3        (2, 1)      e31
prev(e)
v4        (1, 0)      e22
face(e)
face outerComp. innerComp.
e11                              f1      nil        e11
v1                     v2                    f2      e22        nil
f2
e21     edge      origin   twin   face   next   prev
e41
e11        v1      e22    f1     e21   e41
f1                     v3        e12        v2      e11    f2     e42   e22
e32
e21        v2      e22    f1     e31   e11
v4         e31
...
Map Overlay
Input:        subdivisions S1 , S2 as DCELs

S2
S1
Map Overlay
Input:         subdivisions S1 , S2 as DCELs
Output:        DCEL D

D
S2
S1
Map Overlay
Input:         subdivisions S1 , S2 as DCELs
Output:        DCEL D with
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)

D
S2
S1
Map Overlay
Input:         subdivisions S1 , S2 as DCELs
Output:        DCEL D with
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)

D
S2
S1
Map Overlay
Input:         subdivisions S1 , S2 as DCELs
Output:        DCEL D with               interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)

D
S2
S1
Map Overlay
Input:         subdivisions S1 , S2 as DCELs
Output:        DCEL D with               interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)

D
S2
S1
Map Overlay
Input:         subdivisions S1 , S2 as DCELs
Output:        DCEL D with               interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Why do we need the big union? —
D
S2
S1
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
problem:
input = set of segm.
Map Overlay
Input:     subdivisions S1 , S2 as DCELs
Output:    DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:      “recycle” ﬁndIntersections()
problem:
input = set of segm.
Changes:
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
problem:
input = set of segm.
Changes: without ﬁnding/treating faces        [book, p. 36–38]
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
problem:
input = set of segm.
Changes: without ﬁnding/treating faces        [book, p. 36–38]

self-study
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
problem:
input = set of segm.
Changes: without ﬁnding/treating faces        [book, p. 36–38]
• if all segments incident to an event pt belong to
one subdivision, keep going!
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
problem:
input = set of segm.
Changes: without ﬁnding/treating faces        [book, p. 36–38]
• if all segments incident to an event pt belong to
one subdivision, keep going!
• otherwise “stitch” DCELs together
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
problem:
input = set of segm.
Changes: without ﬁnding/treating faces        [book, p. 36–38]
• if all segments incident to an event pt belong to
one subdivision, keep going!
• otherwise “stitch” DCELs together. Cases, e.g.,
Map Overlay
Input:    subdivisions S1 , S2 as DCELs
Output:   DCEL D with            interpreted as line segments
V (D) = V (S1 ) ∪ V (S2 ) ∪ {e1 ∩ e2 | ei ∈ E(Si )}
E(D) = conn. comp. of         E(S1 ) ∪ E(S2 ) \ V (D)
Idea:     “recycle” ﬁndIntersections()
problem:
input = set of segm.
Changes: without ﬁnding/treating faces        [book, p. 36–38]
• if all segments incident to an event pt belong to
one subdivision, keep going!
• otherwise “stitch” DCELs together. Cases, e.g.,
– edge of S1 passes through vertex of S2
– edges of S1 and edges of S2 intersect

```
To top