torsdag 25 mars 2004 SMD156 Computational Geometry - Håkan Jonsson 1 SMD156 Lecture 2 Line segment intersection Boolean operations on polygons Subdivisions Map overlay Doubly-Connected Edge Lists Plane sweep torsdag 25 mars 2004 SMD156 Computational Geometry - Håkan Jonsson 2 Determining whether at least one pair of line segments intersect s 3 s 7 s 1 s 5 s 6 s 2 s 4 torsdag 25 mars 2004 SMD156 Computational Geometry - Håkan Jonsson 3 Line segment intersection • Compute and report all intersections among a set of n line segments. • A trivial solution based on brute-force: ! For each pair of line segments: Compute the point of intersection between the lines that contain the line segments; if this point lie on both line segments, we have found an intersection. ! There are O"n 2 # pairs so this takes O"n 2 # time. • Natural question: Do we really need to spend O"n 2 # time? ! Note that the number of intersections could be much less than O"n 2 #… • Interesting question: Is there a way to relate the running time to the number of intersections that need to be reported? torsdag 25 mars 2004 SMD156 Computational Geometry - Håkan Jonsson 4
5
Embed
Line segment intersection Determining whether at least one
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
• Imagine a horizontal line sweeping downwards overthe plane, starting above all line segments.
• As the sweep line is moved, we keep track of the set ofline segments that it intersects - the status.! The status contains the intersected line segments ordered by
where they intersect the sweep line.
• In general, the status is invariant. It only changeswhen the sweep line reaches an event point.
• An event point is either! an end point of a line segment, or
! a point of intersection between two line segments.
• This happens at an event point when…! An upper end point is reached: Insert the new
line segment "into the status# and test it forintersections with its neighbors below thesweep line; insert the intersection points asevent points, if any.
! An point of intersection is reached: Swap theline segments that intersect and test them forintersections below the sweep line with theirnew neighbors. If they intersect, insert thepoints as new event points.
! A lower end point is reached: Delete the linesegment and test whether the two newneighbors intersect. If they intersect, insert thepoints as new event points.
• AVL-trees, red-black trees, etc thatsupport insertion, deletion, neighbor"successor and predecessor#, andlookup in O!log m" time when the treecontains m items.
! Define an order between the event point"highest first, leftmost to break ties#
• Status! A balanced binary search tree
• "One can store anything - not justnumbers - in such a tree as long as theitems are ordered.#