Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms.

Similar presentations


Presentation on theme: "Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms."— Presentation transcript:

1 Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms

2 Computational geometry Computational geometry is devoted to the study of algorithms which can be stated in terms of geometry.

3 Roadmap Closest pair Geometry sweeping Geometric preliminaries Some basics geometry algorithms Convex hull problem Diameter of a set of points Intersection of line segments

4 Closest pair problem Problem: ClosestPair Input: A set S of n points in the plane Output: The pair p1 = (x1, y1) and p2 = (x2, y2) such that the Euclidean distance between p1 and p2 is minimal. Divide Conquer Combine δlδl δrδr 2δ r δrδr

5 Closest pair problem

6

7

8

9 Where are we? Closest pair Geometry sweeping Geometric preliminaries Some basics geometry algorithms Convex hull problem Diameter of a set of points Intersection of line segments

10 The point p 2 = (x 2, y 2 ) dominates the point p 1 = (x 1, y 1 ), denoted by p 1 ≺ p 2, if x 1 ≤ x 2 and y 1 ≤y 2. p2p2 p1p1 A point p is maximal point if there does NOT exist a point q such that p ≠ q and p ≺ q. p3p3 p4p4 Maximal points problem

11 Sweeping line Θ(nlogn) Problem: MaximalPoints Input: a set of points with their coordinates (x i,y i ). Output: All the maximal points in the set. Event

12 Geometric sweeping Determine the sweeping line and Events Handle events Solve the problem

13 City Skyline 8 (1, 1) (2, 2) (3, 3) (4, 2) (5, 3) (6, 2) (7, 0) (8, 1) 112345678

14 Where are we? Closest pair Geometry sweeping Geometric preliminaries Some basics geometry algorithms Convex hull problem Diameter of a set of points Intersection of line segments

15 Geometry preliminaries Point: p(x,y) Line segment: ((x 1,y 1 ),(x 2,y 2 )) Convex polygon: A polygon P is convex if the line segment connecting any two points in P lies ENTIRELY in P. concaveconvex

16 Left turn and right turn p 1 (x 1,y 1 ) Area = ? p 2 (x 2,y 2 ) p 3 (x 3,y 3 ) p 1 (x 1,y 1 ) p 2 (x 2,y 2 ) p 3 (x 3,y 3 ) D > 0 p 1 (x 1,y 1 ) p 2 (x 2,y 2 ) p 3 (x 3,y 3 ) D < 0

17 Left turn and right turn To determine whether a point is under or above a line segment. To determine if two line segments intersect.

18 Where are we? Closest pair Geometry sweeping Geometric preliminaries Some basics geometry algorithms Convex hull problem Diameter of a set of points Intersection of line segments

19 Convex hull Problem: ConvexHull Input: a set S={p 1, p 2,..., p n } of n points in the plane, Output: CH(S) Graham scan Jarvis’ march (gift-wrapping algorithm) Quick-hull

20 Jarvis’ march Start at some extreme point, which is guaranteed to be on the hull. At each step, test each of the points, and find the one which makes the largest right-hand turn. That point has to be the next one on the hull. p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 O(n 2 )

21 Quick hull Given a chord p i p j of the convex hull Find the farthest one p k from the chord The points inside the triangle p i p j p k cannot be on the hull. Put the points which lie outside edge p i p k in set s1, and points outside edge p j p k in set s2. Recursively solve the problem of s1 and s2. p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 O(n 2 ) http://www.cs.princeton.edu/courses/archive/fall10/cos226/demo/ah/ConvexHull.h tml

22 Graham Scan Ronald Graham (source from Wikipedia) p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10

23 Graham scan p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10

24 Geometric sweeping Sweeping line and Events How to handle events Solve the problem p0p0 p1p1 p2p2 p3p3 p4p4 p5p5 p6p6 p7p7 p8p8 p9p9 p 10 Θ(nlogn)+ O(n)

25

26 Where are we? Closest pair Geometry sweeping Geometric preliminaries Some basics geometry algorithms Convex hull problem Diameter of a set of points Intersection of line segments

27 The diameter of a set of points p 12 p1p1 p2p2 p4p4 p6p6 p8p8 p 10 p9p9 p3p3 p5p5 p7p7 p 11 The diameter of a set P of points equals to the diameter of CH(P). Any two points that admit two parallel supporting lines are called antipodal pair. Any pair of vertices realizing the diameter in a convex polygon is an antipodal pair. How to find antipodal pairs?

28 p 12 p1p1 p2p2 p4p4 p6p6 p8p8 p 10 p9p9 The diameter of a set of points How many antipodal pairs?

29 Rotating caliper p 12 p1p1 p2p2 p4p4 p6p6 p8p8 p 10 p9p9 m + m/2 antipodal pairs, m ≤ n

30 Θ(nlogn)

31 Union of 2 convex polygons

32 Intersection of orthogonal line segments Sweep vertical line from left to right. x-coordinates define events. h-segment (left endpoint): insert y-coordinate into BST. h-segment (right endpoint): remove y-coordinate from BST. v-segment: range search for interval of y-endpoints. 0 1 2 3 0 1 3 2 4

33 Intersection of orthogonal line segments Sweep vertical line from left to right. x-coordinates define events. h-segment (left endpoint): insert y-coordinate into BST. h-segment (right endpoint): remove y-coordinate from BST. v-segment: range search for interval of y-endpoints. 4 0 1 2 3 0 1 3

34 Intersection of orthogonal line segments 1d range search. Find all keys between lo and hi. Review: Binary Search Tree Proposition. Running time is proportional to R + log N (assuming BST is balanced). Pf. Nodes examined = search path to lo + search path to hi + matching keys.

35 Intersection of orthogonal line segments 4 0 1 2 3 Θ(nlogn + m)

36 Intersections of line segments Problem: Intersections Input: a set L={l 1, l 2,..., l n } of n line segments in the plane, Output: the set of points in which they intersect. Assume that NO three line segments intersect at the same point.

37 Intersections of line segments 1. If a and b intersects, then at some time (before the intersection point), a and b are adjacent on the sweeping line. 2. When the sweeping line passes the intersection point of a,b, then the order of a, b will be reversed.

38 Intersections of line segments Sweep endpoints and intersect points from left to right left endpoints of l, insert l, and see whether l intersects with above(l) and below(l); if so, add the intersect points. right endpoints of l, remove l, and see whether above(l) and below(l) intersect; if so, add the intersect point; intersect point of (l,l’); see whether l and below(l’); I’ and above(l) intersect; if so, add the intersect point; swap (l,l’). edbedb edbfedbf ebdfebdf bedfbedf Θ(nlogn+ (m+n)logn) http://www.cs.princeton.edu/courses/archive/fall10/cos226/demo/gishur/

39 Intersections of line segments

40 Θ(nlogn+ (m+n)logn)

41 Where are we? Diameter of a set of points Intersection of line segments Intersection of rectangles Nearest neighbor search

42 Intersection of rectangles 0 1 2 3 Microprocessor design became a geometric problem. Certain wires cannot intersect. Certain spacing needed between different types of wires. Debugging = orthogonal rectangle intersection search.

43 Intersection of rectangles Sweep vertical line from left to right. x-coordinates of left and right endpoints define events. Maintain set of rectangles that intersect the sweep line in an interval search tree (using y-intervals of rectangle). Left endpoint: interval search for y-interval of rectangle; insert y-interval. Right endpoint: remove y-interval. y-coordinates 0 1 2 3 0 1 2 3

44 Interval search tree binary search tree (left endpoint is key) (17, 19) (5, 8)(21, 24) (4, 8)(15, 18) (7, 10) 24 18 8 10 24 max endpoint in subtree rooted at node Insertion = BST insertion

45 Interval search tree Search (lo, hi ) : If interval in node intersects query interval, return it. If left subtree is null, go right. If max endpoint in left subtree is less than lo, go right. Else go left. interval intersection search for (23, 25) (12, 14) (21, 23) (17, 19) (5, 8)(21, 24) (4, 8)(15, 18) (7, 10) 24 22 8 10 24 22 (16, 22)

46 Flocking birds http://www.youtube.com/watch?v=XH-groCeKbE

47 Simulation of Flocking birds

48 2d-tree Recursively partition plane into two halfplanes. 1 2 3 4 6 7 8 9 10 5 1 2 8 7 9 3 4 6 5

49 Conclusion Computational geometry is devoted to the study of algorithms which can be stated in terms of geometry. Computational complexity: the difference between O(n 2 ) and O(n log n) may be the difference between days and seconds of computation. Applications include: CAD/CAM, GIS, Integrated Circuit design, Computer vision, ……

50 References [1] Franco P. Preparata and Michael Ian Shamos. Computational Geometry - An Introduction.Franco P. Preparata Computational Geo Springer-Verlag. [2] Mark de Berg, Otfried Cheong,Marc van Kreveld, Mark Overmars.tfried Cheong,Mark Overmars. CComputational Geometry: Algorithms and ApplicationsThird Edition (March 2008) Springer- Verlag.try: AlgorithmonsThird Editionnger- Verlag.


Download ppt "Lecture 15 Computational Geometry Geometry sweeping Geometric preliminaries Some basics geometry algorithms."

Similar presentations


Ads by Google