23
Yazd Univ. Computational Geometry Line Segment Intersection Problem Plane sweep algorithm Line Segment Intersection 1388-1389

Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

Yazd Univ.

ComputationalGeometry

Line SegmentIntersectionProblem

Plane sweep algorithm

Line Segment Intersection

1388-1389

Page 2: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 3: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 4: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 5: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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

Page 6: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 7: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 8: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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

Page 9: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

`

Page 10: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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

Page 11: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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

Page 12: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 13: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 14: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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

`

Page 15: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 16: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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

`

Page 17: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 18: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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`

Page 19: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 20: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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 `

Page 21: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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.

Page 22: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

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 `

Page 23: Yazd Univ. Line Segment Intersection Computational ...bayanbox.ir/view/2381452891648259872/Line-segment-inter.pdf · Line Segment Intersection Problem Plane sweep algorithm Problem

Yazd Univ.

ComputationalGeometry

Line SegmentIntersectionProblem

Plane sweep algorithm