1 / 19

Computational Geometry

Computational Geometry. Hwangryol Ryu Dongchul Kim. Computational Geometry. Intersection of line segment Basic geometric objects Point : ( x, y ) Line : {( x 1 ,y 1 ) , ( x 2 ,y 2 ) } Line segment : size of line is given. ( x 2, y 2 ). ( x 2, y 2 ). ( x 1, y 1 ). ( x 1, y 1 ).

kaycee
Télécharger la présentation

Computational Geometry

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ComputationalGeometry Hwangryol Ryu Dongchul Kim

  2. Computational Geometry • Intersection of line segment • Basic geometric objects • Point : ( x, y ) • Line : {(x1,y1) , (x2,y2) } • Line segment : size of line is given (x2,y2) (x2,y2) (x1,y1) (x1,y1)

  3. Basic geometric objects(contd) • Polygon Convex Non-convex • Convex : Each indegree less than 180

  4. Intersection of line segment • Input : a pair of line segments • Output : yes – if they intersect no – otherwise • How do we know that intersection(x,y) exits between two lines? (x, y)

  5. Intersection of line segment(…contd) (x2,y2) Algorithm Find equation of first segment Y=m1x+c1 Find equation of second segment Y=m2x+c2 Find intersection of two lines : (x,y) • If ( x1 < x < x2 ) && ( x3 < x < x4 ) Then return (Intersection exits) • Else return (No intersection exits) (x1,y1) (x, y) (x3,y3) (x4,y4)

  6. Intersection of line segment(…contd) Is there a pair of line segments intersecting each other? • Naive algorithm: Check each two segments for intersection. Complexity: O(n2).

  7. Plane Sweep – Algorithm • Event is any end point or intersection point. • Sweep the plane using a vertical line. • Maintain two data structures: • Event priority queue – sorted by x coordinate. • Sweep line status – Stores segments currently intersected by sweep line and maintain Red-Black Tree to support data structure.

  8. Plane Sweep – Algorithm • Problem: Given n segments in the plane, compute all their intersections. • Assume: • No line segment is vertical. • No two segments are collinear. • No three segments intersect at a common point. • Event is any end point or intersection point. • Sweep the plane using a vertical line. • Maintain two data structures: • Event priority queue – sorted by x coordinate. • Sweep line status – Stores segments currently intersected by sweep line, sorted by y coordinate.

  9. Plane Sweep - Basic Idea We are able to identify all intersections by looking only at adjacent segments in the sweep line status during the sweep. Theorem: Just before an intersection occurs, the two relevant segments are adjacent to each other in the sweep line status.

  10. Plane Sweep - Basic Idea(contd) In practice: Look ahead: whenever two line segments become adjacent along the sweep line, check for their intersection to the right of the sweep line.

  11. Plane Sweep – Algorithm • Initialization: • Add all segments’ endpoints to the event queue (O(nlog n)). • Sweep line status is empty. • Algorithm proceeds by inserting and deleting discrete events from the queue until it is empty.

  12. Plane Sweep – Algorithm • Event A: Beginning of segment • Insert segment into sweep line status. • Test for intersection to the right of the sweep line with the segments immediately above and below. Insert point (if found) into event queue. • Complexity: n such events, O(log n) each  O(n log n) total.

  13. Plane Sweep – Algorithm • Event B: End of segment • Delete segment from sweep line status. • Test for intersection to the right of the sweep line between the segments immediately above and below. Insert point (if found) into event queue. • Complexity: n such events, O(log n) each  O(n log n) total.

  14. Plane Sweep – Algorithm • Event C: Intersection point • Report the point. • Swap the two line relevant segments in the sweep line status. • For the new upper segment – test it against its predecessor for an intersection. Insert point (if found) into event queue. • Similar for new lower segment (with successor). • Complexity: k such events, O(logn) each  O(klogn) total.

  15. Plane Sweep – Example a3 b4 Ex1) s3 e1 s4 a2 a4 b3 s2 b1 b0 s1 b2 s0 a1 a0 Sweep Line Status Event Queue s0,s1,s2,s3 a4, b1, b2, b0, b3, b4

  16. Plane Sweep – Example a3 b4 s3 e1 s4 a2 a4 b3 s2 b1 b0 s1 b2 s0 a1 a0 Insert s4 to SLS Test s4-s3 and s4-s2. Add e1 to EQ s0,s1,s2, s4, s3 b1, e1, b2, b0, b3, b4 Action Sweep Line Status Event Queue

  17. Plane Sweep – Example a3 b4 s3 e1 s4 a2 a4 b3 s2 e2 b0 b1 s1 b2 s0 a1 a0 Delete s1 from SLS Test s0-s2. Add e2 to EQ s0,s2,s4,s3 e1, e2, b2, b0, b3, b4 Action Sweep Line Status Event Queue

  18. Plane Sweep – Example a3 b4 s3 e1 s4 a2 a4 b3 s2 e2 b0 b1 s1 b2 s0 a1 a0 Swap s3 and s4 . Test s3-s2. s0,s2,s3,s4 e2, b2, b0, b3, b4 Action Sweep Line Status Event Queue

  19. Plane Sweep – Complexity Analysis • Total time complexity: O((n+k) logn). If kn2 this is almost like the naive algorithm. • Event queue: heap • Sweep line status: balanced binary tree • Total space complexity: O(n+k).

More Related