 # Computational Geometry

## Presentation on theme: "Computational Geometry"— Presentation transcript:

Computational Geometry
Hwangryol Ryu Dongchul Kim

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)

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

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)

Intersection of line segment(…contd)
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) (x2,y2) (x1,y1) (x, y) (x3,y3) (x4,y4)

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

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.

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.

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.

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.

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.

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.

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.

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.

Plane Sweep – Example Ex1) s3 e1 s4 s2 s1 s0 Sweep Line Status
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

Plane Sweep – Example s3 e1 s4 s2 s1 s0 Insert s4 to SLS
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

Plane Sweep – Example s3 e1 s4 s2 e2 s1 s0 Delete s1 from SLS Action
b4 s3 e1 s4 a2 a4 b3 s2 e2 b0 s1 b1 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

Plane Sweep – Example s3 e1 s4 s2 e2 s1 s0 Swap s3 and s4 . Action
b4 s3 e1 s4 a2 a4 b3 s2 e2 b0 s1 b1 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

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