Download presentation

Presentation is loading. Please wait.

Published byMadalyn Sandall Modified about 1 year ago

1
Computational Geometry Hwangryol Ryu Dongchul Kim

2
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 1, y 1 ) (x 2, y 2 ) (x 1, y 1 )

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) (x, y) (x 4, y 4 ) (x 3, y 3 ) (x 2, y 2 ) Algorithm Find equation of first segment Y=m 1 x+c 1 Find equation of second segment Y=m 2 x+c 2 Find intersection of two lines : (x,y) -If ( x 1 < x < x 2 ) && ( x 3 < x < x 4 ) Then return (Intersection exits) -Else return (No intersection exits) (x 1, y 1 )

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(n 2 ).

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 Theorem: Just before an intersection occurs, the two relevant segments are adjacent to each other in the sweep line status. We are able to identify all intersections by looking only at adjacent segments in the sweep line status during the sweep.

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(n log 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 s4 s2 s1 s0 s3 s0,s1,s2,s3 a4, b1, b2, b0, b3, b4 e1 Sweep Line Status Event Queue a1 b1 a0 b0 a2 b2 a4 a3 b3 b4 Ex1)

16
Plane Sweep – Example s4 s2 s1 s0 s3 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 e1 Action Sweep Line Status Event Queue a1 b1 a0 b0 a2 b2 a4 a3 b3 b4

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

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

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

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google