Upload
others
View
13
Download
0
Embed Size (px)
Citation preview
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Line Segment Intersection
1388-1389
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Problem
Line segment intersection problem:Given two sets of line segments, compute allintersections between a segment from one set and asegment from the other.
? We consider the segments to be closed.
Simplified version:
Given a set S of n closed segmentsin the plane, report all intersectionpoints among the segments in S.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Problem
Line segment intersection problem:Given two sets of line segments, compute allintersections between a segment from one set and asegment from the other.
? We consider the segments to be closed.
Simplified version:
Given a set S of n closed segmentsin the plane, report all intersectionpoints among the segments in S.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
1st algorithm
The brute-force algorithm clearly requires O(n2)time.In a sense this is optimal: when each pair ofsegments intersects any algorithm must take Ω(n2)time, because it has to report all intersections.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
1st algorithm
The brute-force algorithm clearly requires O(n2)time.In a sense this is optimal: when each pair ofsegments intersects any algorithm must take Ω(n2)time, because it has to report all intersections.
n/2 lines
n/2
lines
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Output sensitive algorithm
Definition:An algorithm whose running time depends not only on thenumber of segments in the input, but also on the numberof intersection points.
In our case:We want an algorithm that runs faster when the numberof intersections is sub-quadratic.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Output sensitive algorithm
Definition:An algorithm whose running time depends not only on thenumber of segments in the input, but also on the numberof intersection points.
In our case:We want an algorithm that runs faster when the numberof intersections is sub-quadratic.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithm
y-intervalsDefine the y-interval of a segmentto be its orthogonal projection ontothe y-axis.When the y-intervals of a pair ofsegments do not overlap then theycannot intersect.To find segments whose y-intervalsoverlap we use a Plane sweepalgorithm.
y
x
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmPlane sweep algorithm
We imagine sweeping a line ` downwards over theplane, starting from a position above all segments.While we sweep the imaginary line, we keep track ofall segments intersecting it so that we can find thepairs we need.
`
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmPlane sweep algorithm
We imagine sweeping a line ` downwards over theplane, starting from a position above all segments.While we sweep the imaginary line, we keep track ofall segments intersecting it so that we can find thepairs we need.
event point
`
sweep line
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmwhen the sweep line reaches an event point:
If the event point is the upper endpoint of a segment,then a new segment starts intersecting the sweepline and must be added to the status.If the event point is a lower endpoint, a segmentstops intersecting the sweep line and must bedeleted from the status.If the algorithm test pairs of segments for which thereis a horizontal line that intersects both segments.(still quadratic).
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmNew algorithm:
Order the segments from left to right as theyintersect the sweep line.Test adjacent segments in the horizontal ordering forintersection.To maintain the sorted list, we need to take care ofnew event points.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmNew algorithm:
Order the segments from left to right as theyintersect the sweep line.Test adjacent segments in the horizontal ordering forintersection.To maintain the sorted list, we need to take care ofnew event points.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmNew algorithm:
Order the segments from left to right as theyintersect the sweep line.Test adjacent segments in the horizontal ordering forintersection.To maintain the sorted list, we need to take care ofnew event points.
new neighbors
sj sksl sm
`
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmDo we still find all intersections?Lemma 2.1 Let si and sj be two non-horizontal segmentswhose interiors intersect in a single point p, and assumethere is no third segment passing through p. Then thereis an event point above p where si and sj becomeadjacent and are tested for intersection.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmDo we still find all intersections?Lemma 2.1 Let si and sj be two non-horizontal segmentswhose interiors intersect in a single point p, and assumethere is no third segment passing through p. Then thereis an event point above p where si and sj becomeadjacent and are tested for intersection.
sisj
p
`
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmHandling event points:The event point is the upper endpoint of a segment:
Insert the new segment in the sorted list.Check for intersection between the new segment andthe segment before and after it in the sorted list.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmHandling event points:The event point is the upper endpoint of a segment:
Insert the new segment in the sorted list.Check for intersection between the new segment andthe segment before and after it in the sorted list.
intersectiondetected
si
sj
sk`
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmHandling event points:The event point is an intersection:
Change the order of intersected segments in thesorted list.For each intersected segment, check for intersectionbetween the segment and the new neighbor in thesorted list.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmHandling event points:The event point is an intersection:
Change the order of intersected segments in thesorted list.For each intersected segment, check for intersectionbetween the segment and the new neighbor in thesorted list.
sj sksl sm `
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmHandling event points:The event point is a lower endpoint:
Remove the segments from the sorted list.check for intersection between the neighboringsegments.
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm
Plane sweep algorithmHandling event points:The event point is a lower endpoint:
Remove the segments from the sorted list.check for intersection between the neighboringsegments.
sk sl sm `
Yazd Univ.
ComputationalGeometry
Line SegmentIntersectionProblem
Plane sweep algorithm