line segment intersection
DESCRIPTION
Line Segment Intersection. Chapter 2 of the Textbook Driving Applications Map overlap problems 3D Polyhedral Morphing. Thematic Map Overlay. GIS systems split each map into several layers Each layer is called a thematic map , storing one type of information - PowerPoint PPT PresentationTRANSCRIPT
UNC Chapel Hill M. C. Lin
Line Segment Intersection
Chapter 2 of the Textbook
Driving Applications–Map overlap problems– 3D Polyhedral Morphing
UNC Chapel Hill M. C. Lin
Thematic Map Overlay
GIS systems split each map into several layers
Each layer is called a thematic map, storing one type of information
Find overlay of several maps to locate interesting junctions
UNC Chapel Hill M. C. Lin
Transform to a Geometric Problem
Curves can be approximated by small (line) segments
Each thematic map can be viewed as a collection of line segments
Finding the overlay of two networks => computing all intersection points between the line segments of two sets
UNC Chapel Hill M. C. Lin
Let’s Be More Serious & Precise...
Segments closed or open?– Take a look at the original problem =>
should be closed
To simplify further, make 2 sets into 1– But, how do we identify the really
interesting one? Filter them out by checking if they are from the same set.
UNC Chapel Hill M. C. Lin
Problem Analysis
Brute Force Approach: O(n2) Desiderata: output(intersection) sensitive – Segments that are close together are the
candidates for intersection
x
y
UNC Chapel Hill M. C. Lin
Plane Sweep Algorithm
Status of l: the set of segments intersecting l Event points: where updates are required
l : sweep line
event point
UNC Chapel Hill M. C. Lin
Plane Sweep Algorithm (cont)
At a event point: update the status of the sweep line & perform intersection testsUpper: a new segment is added to the status of l
and it’s tested against the rest
Lower: it’s deleted from the status of l
=> Only testing pairs of segments for which there is a horizontal line intersects both segments.
=> But, this is not good enough. It may still be inefficient, O(n2) for some cases. (ex) a set of segments all intersect with x-axis.
UNC Chapel Hill M. C. Lin
Plane Sweep Algorithm (cont)
To include the idea of being close in the horizontal direction, only test segments that are adjacent in the horizontal direction --
Only test each with ones to its left and right New “status”: ordered sequence of segments New “event points”: endpoints and intersects
l
Sj Sk SlSm
UNC Chapel Hill M. C. Lin
Nasty Cases (Degeneracies)
Horizontal lines
Overlapping line segments
Multiple line segments intersect at one single point
UNC Chapel Hill M. C. Lin
Plane-Sweep Algorithm (Recap)
Move a horizontal sweep line l downwards
Halt l at event points (end pts & intersects)
While l moves, maintain ordered sequence of segments intersected by it
When l halts at an event point, the sequence of segments changes, status of l needs to be updated and to detect intersections depending on type of events
UNC Chapel Hill M. C. Lin
Event Types
NOTE: only intersection points below l are important, assuming all intersection points above l have been computed correctly.
Upper end point: If Si and Sk are adjacent on l, a new upper end point of Sj appears, check Sj with Si and Sk for intersections
Intersection point of 2 lines: Change their order. Each gets (at most) 1 new neighbor
Lower end point: Its two neighbors are now adjacent and must be tested for intersection below the sweep line l
UNC Chapel Hill M. C. Lin
Data Structure
Type: Event queue that stores events
Operations– remove next event and return it to be treated– among 2 events with the same y-coordinate, the
one with smaller x-coordinate is returned
(left-to-right priority order)– allow for insertions & check if it is already there– allow 2++ event points to coincide
(ex) two upper end points coincide
UNC Chapel Hill M. C. Lin
Implementing Event Queue
Define an order on event points, according to which they will be handled
Store the event points in a balanced binary search tree T according to their orders– both fetching & insertion takes O(log m) time, where m is
the number of events
Maintain the status of l using T– the left-to-right order of segments on the line l <=> the
left-to-right order of leaves in T– segments in internal nodes guide search– each update and search takes O(log m)
UNC Chapel Hill M. C. Lin
Status Structure, T
lSjSk Sl SmSi
Si
Sj Sk
Sl Sm
Si
Sj
Sk
SlT
UNC Chapel Hill M. C. Lin
FindIntersections (S)
Input : a set S of line segments in a plane Output : a set of intersections and their
associated line segments in S
1. Initialize Q. Insert the end points into Q
with their corresponding segments
2. Initialize an empty status structure T
3. While Q is not empty
4. Do Find next event point p in Q & delete it
5. HandleEventPoint (p)
UNC Chapel Hill M. C. Lin
Handling Changes in Status
l
S4
S1
S3 S8S7
S5
S2
S1S3
UNC Chapel Hill M. C. Lin
Handling Changes in Status
S7 S3
S1 S8
S3
S2
S1
S2
S7
T
S1
S3 S8
S5
S4
S1
S3
S7 S5S4
S7
T
S2
l
S4
S1
S3 S8S7S5
S1S3
UNC Chapel Hill M. C. Lin
HandleEventPoint (p)
1. Let U(p) be set of segments whose upper end point is p
2. Search in T for set S(p) of all segments that contains p;
they are adjacent in T. Let L(p) S(p) be the set of
segments whose lower endpts in p and C(p) S(p) be
the set of segments that contains p in its interior
3. If L(p) U(p) C(p) contains more than 1 segment
4. then Report p as an intersect with L(p), U(p) and C(p)
5. Delete segments in L(p) C(p) from T
6. Insert segments in U(p) C(p) into T. Order segments
in T according to their order on sweep line just below p.
A horizontal one comes last among all containing p.
UNC Chapel Hill M. C. Lin
HandleEventPoint (p)
7. (Deleting & re-inserting segments of C(p) reverses order)
8. If U(p) C(p) = 0
9. then Let sl and sr be the left/right neighbors of p in T
10. FindNewEvent(sl , sr , p)
11. else Let s’ be the left most segment of U(p) C(p) in T
12. Let sl be the left neighbor of s’ in T
13. FindNewEvent(sl , s’, p)
14. Find s’’ be rightmost segment of U(p) C(p) in T
15. Let sr be the right neighbor of s’’ in T
16. FindNewEvent(s’’, sr , p)
UNC Chapel Hill M. C. Lin
FindNewEvent (sl, sr, p)
1. If sl and sr intersect below the sweep line, or on it and to the right of current point p, and the intersection is not yet present as an event in Q
2. Then Insert the intersection point as an event into Q
UNC Chapel Hill M. C. Lin
Algorithm Analysis
Let S be a set of n segments in a plane
All intersections in S can be reported in– O(n log n + I log n) time– O(n) space– where I is the number of intersection points
UNC Chapel Hill M. C. Lin
Doubly-Connected Edge List
3 records: vertices, faces and “half-edges”
Vertex: coordinates(v) & a ptr to a half-edge
Face: – OuterComponent(f): bounding edges
– InnerComponent(f): edges on the boundary of holes contained in the face, f
Edge: a ptr to Origin(e), a ptr to a twin-edge, ptrs to Next(e) & Prev(e) edges and its left IncidentFace(e)
UNC Chapel Hill M. C. Lin
Computing Overlay of Subdivisions
Let S1, S2 be two planar subdivisions of complexity n1 and n2 respectively; and let n = n1 + n2
Overlay of S1 and S2 can be constructed in O(n log n + k log n) time, where k is the complexity of overlay
UNC Chapel Hill M. C. Lin
Boolean Operations
Let P1, P2 be two polygons with n1 and n2 vertices respectively; and let n = n1 + n2
Their boolean operations (intersection, union, and difference) can each be computed in O(n log n + k log n) time, where k is the complexity of the output