A Tutorial on Computational Geometry

5,970 views

Published on

My talk about computational geometry in NTU's APEX Club in NTU, Singapore in 2007. The club is for people who are keen on participating in ACM International Collegiate Programming Contests organized by IBM annually.

Published in: Technology

A Tutorial on Computational Geometry

  1. 1. A Tutorial on Computational Geometry Pham Minh Tri Ph.D. Candidate and Project Officer School of Computer Engineering 1 Mar 2008 presented by
  2. 2. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  3. 3. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  4. 4. Point Inside Polygon Test <ul><li>Given a point, determine </li></ul><ul><li>if it lies inside a polygon </li></ul><ul><li>or not </li></ul>
  5. 5. Ray Test <ul><li>Fire ray from point </li></ul><ul><li>Count intersections </li></ul><ul><ul><li>Odd = inside polygon </li></ul></ul><ul><ul><li>Even = outside polygon </li></ul></ul>
  6. 6. Problems With Rays <ul><li>Fire ray from point </li></ul><ul><li>Count intersections </li></ul><ul><ul><li>Odd = inside polygon </li></ul></ul><ul><ul><li>Even = outside polygon </li></ul></ul><ul><li>Problems </li></ul><ul><ul><li>Ray through vertex </li></ul></ul>
  7. 7. Problems With Rays <ul><li>Fire ray from point </li></ul><ul><li>Count intersections </li></ul><ul><ul><li>Odd = inside polygon </li></ul></ul><ul><ul><li>Even = outside polygon </li></ul></ul><ul><li>Problems </li></ul><ul><ul><li>Ray through vertex </li></ul></ul>
  8. 8. Problems With Rays <ul><li>Fire ray from point </li></ul><ul><li>Count intersections </li></ul><ul><ul><li>Odd = inside polygon </li></ul></ul><ul><ul><li>Even = outside polygon </li></ul></ul><ul><li>Problems </li></ul><ul><ul><li>Ray through vertex </li></ul></ul><ul><ul><li>Ray parallel to edge </li></ul></ul>
  9. 9. A Better Way
  10. 10. A Better Way
  11. 11. A Better Way
  12. 12. A Better Way
  13. 13. A Better Way
  14. 14. A Better Way
  15. 15. A Better Way
  16. 16. A Better Way
  17. 17. A Better Way
  18. 18. A Better Way
  19. 19. A Better Way
  20. 20. A Better Way <ul><li>One winding = inside </li></ul>
  21. 21. A Better Way
  22. 22. A Better Way
  23. 23. A Better Way
  24. 24. A Better Way
  25. 25. A Better Way
  26. 26. A Better Way
  27. 27. A Better Way
  28. 28. A Better Way
  29. 29. A Better Way
  30. 30. A Better Way
  31. 31. A Better Way
  32. 32. A Better Way <ul><li>zero winding = outside </li></ul>
  33. 33. Requirements <ul><li>Oriented edges </li></ul><ul><li>Edges can be processed </li></ul><ul><li>in any order </li></ul>
  34. 34. Computing Winding Number <ul><li>Given unit normal n </li></ul><ul><li>=0 </li></ul><ul><li>For each edge ( p 1 , p 2 ) </li></ul><ul><li>for some integer k </li></ul><ul><li>k = winding number </li></ul><ul><ul><li>If k == 1 , then inside </li></ul></ul><ul><ul><li>If k == 0 , then outside </li></ul></ul>
  35. 35. Advantages <ul><li>Extends to 3D! </li></ul><ul><li>Numerically stable </li></ul><ul><li>Even works on models with holes: </li></ul><ul><ul><li>Odd k : inside </li></ul></ul><ul><ul><li>Even k : outside </li></ul></ul><ul><li>No ray casting </li></ul>
  36. 36. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  37. 37. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  38. 38. Convex Hulls Subset of S of the plane is convex, if for all pairs p,q in S the line segment pq is completely contained in S. The C onvex Hull CH(S) is the smallest convex set, which contains S. p q pq p q pq
  39. 39. Convex hull of a set of points in the plane The convex hull of a set P of points is the unique convex polygon whose vertices are points of P and which contains all points from P. Rubber band experiment
  40. 40. Convex Hull <ul><li>Input: </li></ul><ul><ul><li>Set S = {s 1 , …, s n } of n points </li></ul></ul><ul><li>Output: </li></ul><ul><ul><li>Find its convex hull </li></ul></ul><ul><li>Many algorithms: </li></ul><ul><ul><li>Naïve – O ( n 3 ) </li></ul></ul><ul><ul><li>Insertion – O ( n log n ) </li></ul></ul><ul><ul><li>Divide and Conquer – O ( n log n ) </li></ul></ul><ul><ul><li>Gift Wrapping – O ( nh ), h = no of points on the hull </li></ul></ul><ul><ul><li>Graham Scan – O ( n log n ) </li></ul></ul>
  41. 41. Graham Scan <ul><li>Polar sort the points around a point inside the hull </li></ul><ul><li>Scan points in counter-clockwise (CCW) order </li></ul><ul><ul><li>Discard any point that causes a clockwise (CW) turn </li></ul></ul><ul><ul><ul><li>If CCW, advance </li></ul></ul></ul><ul><ul><ul><li>If !CCW, discard current point and back up </li></ul></ul></ul>
  42. 42. Graham-Scan : (1/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12
  43. 43. Graham-Scan :(1/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 1.Calculate polar angle 2.Sorted by polar angle
  44. 44. Graham-Scan : (2/11) p 2 p 1 p 0 Stack S : p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12
  45. 45. Graham-Scan : (3/11) Stack S : p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 3 p 1 p 0
  46. 46. Graham-Scan : (4/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 4 p 3 p 1 p 0 Stack S :
  47. 47. Graham-Scan (5/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 5 p 3 p 1 p 0 Stack S :
  48. 48. Graham-Scan (6/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 8 p 7 p 6 p 5 p 3 p 1 p 0 Stack S :
  49. 49. Graham-Scan (7/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 9 p 6 p 5 p 3 p 1 p 0 Stack S :
  50. 50. Graham-Scan (8/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 10 p 3 p 1 p 0 Stack S :
  51. 51. Graham-Scan (9/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 11 p 10 p 3 p 1 p 0 Stack S :
  52. 52. Graham-Scan (10/11) p 1 p 0 p 3 p 4 p 2 p 5 p 6 p 7 p 8 p 9 p 10 p 11 p 12 p 12 p 10 p 3 p 1 p 0 Stack S :
  53. 53. Time complexity Analysis <ul><li>Graham-Scan </li></ul><ul><ul><li>Sorting in step 2 needs O ( n log n ) . </li></ul></ul><ul><ul><li>Time complexity of stack operation is O(2 n) </li></ul></ul><ul><ul><li>The overall time complexity in Graham-Scan is O ( n log n ) . </li></ul></ul><ul><li>Demo: </li></ul><ul><ul><li>http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html </li></ul></ul>
  54. 54. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  55. 55. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  56. 56. Line segment intersection <ul><li>Input: </li></ul><ul><ul><li>Set S = {s 1 , …, s n } of n line segments, s i = (x i , y i ) </li></ul></ul><ul><li>Output: </li></ul><ul><ul><li>k = All intersection points among the segments in S </li></ul></ul>
  57. 57. Line segment intersection <ul><li>Worst case: </li></ul><ul><ul><li>k = n ( n –1)/2 = O ( n 2 ) intersections </li></ul></ul><ul><li>Sweep line algorithm (near optimal algorithm): </li></ul><ul><ul><li>O ( n log n + k ) time and O ( n ) space </li></ul></ul><ul><ul><li>O( n ) space </li></ul></ul>
  58. 58. Sweep Line Algorithm Avoid testing pairs of segments that are far apart . Idea : imagine a vertical sweep line passes through the given set of line segments, from left to right. Sweep line
  59. 59. Assumption on Non-degeneracy No segment is vertical. // the sweep line always hits a segment at // a point. If a segment is vertical, imagine we rotate it clockwise by a tiny angle. This means: For each vertical segment, we will consider its lower endpoint before upper point.
  60. 60. Sweep Line Status The set of segments intersecting the sweep line. It changes as the sweep line moves, but not continuously . Updates of status happen only at event points . left endpoints right endpoints intersections event points A G C T
  61. 61. Ordering Segments <ul><li>A total order over the segments that intersect the current </li></ul><ul><li>position of the sweep line: </li></ul><ul><li>Based on which parts of the segments we are </li></ul><ul><li>currently interested in </li></ul>A B C D E B > C > D (A and E not in the ordering) C > D (B drops out of the ordering) At an event point, the sequence of segments changes:  Update the status.  Detect the intersections. D > C (C and D swap their positions)
  62. 62. Status Update (1) <ul><li>A new segment L intersecting </li></ul><ul><li>the sweep line </li></ul>L M K <ul><li>Check if L intersects with the </li></ul><ul><li>segment above ( K ) and the </li></ul><ul><li>segment below ( M ). </li></ul>new event point <ul><li>Intersection(s) are new event </li></ul><ul><li>points. </li></ul>Event point is the left endpoint of a segment. N K, M, N K, L, M, N O
  63. 63. Status Update (2) <ul><li>The two intersecting segments </li></ul><ul><li>( L and M ) change order. </li></ul>L M K <ul><li>Check intersection with new </li></ul><ul><li>neighbors ( M with O and L with N ). </li></ul><ul><li>Intersection(s) are new event points. </li></ul>Event point is an intersection. N O O, L, M, N O, M, L, N
  64. 64. Status Update (3) <ul><li>The two neighbors ( O and L ) </li></ul><ul><li>become adjacent. </li></ul>L M K <ul><li>Check if they ( O and L ) intersect. </li></ul><ul><li>Intersection is new event point. </li></ul>Event point is a lower endpoint of a segment. N O, M, L, N O, L, N O
  65. 65. Data Structure for Event Queue Data structure: balanced binary search tree (e.g., red - black tree). Ordering of event points: by x -coordinates by y -coordinates in case of a tie in x -coordinates. Supports the following operations on a segment s .  inserting an event  fetching the next event Every event point p is stored with all segments starting at p . // O (log m ) // O (log m ) m = # event points in the queue
  66. 66. Data Structure for Sweep-line Status Describes the relationships among the segments intersected by the sweep line. Use a balanced binary search tree T to support the following operations on a segment s . Insert( T , s ) Delete( T , s ) Above( T , s ) // segment immediately above s Below( T , s ) // segment immediately below s e.g , Red - black trees, splay trees ( key comparisons replaced by cross-product comparisons ) . O (log n ) for each operation.
  67. 67. An Example L K M N O K L O N M K L N O  The bottom-up order of the segments correspond to the left-to-right order of the leaves in the tree T .  Each internal node stores the segment from the rightmost leaf in its left subtree.
  68. 68. The Algorithm <ul><li>FindIntersections( S ) </li></ul><ul><li>Input : a set S of line segments </li></ul><ul><li>Ouput : all intersection points and for each intersection the </li></ul><ul><li>segment containing it. </li></ul><ul><li>1 . Q  // initialize an empty event queue </li></ul><ul><li>2. Insert the segment endpoints into Q // store with every left endpoint </li></ul><ul><li>// the corresponding segments </li></ul><ul><li>3. T   // initialize an empty status structure </li></ul><ul><li>while Q   </li></ul><ul><li>do extract the next event point p </li></ul><ul><li>6. Q  Q – { p } </li></ul><ul><li>7. HandleEventPoint( p ) </li></ul>
  69. 69. Handling Event Points Status updates (1) – (3) presented earlier. Degeneracy : several segments are involved in one event point (tricky). T: (a) Delete D, E, A, C (b) Insert B , A, C p A B C C A D G E H l D D A G E H C A C G E G C H A B A G C B
  70. 70. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  71. 71. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  72. 72. Motivation Transformation of a topographic map into a perspective view
  73. 73. Terrains Given: A number of sample points p 1 ..., p n Requir ed: A triangulation T of the points resulting in a “realistic” terrain. &quot;Flipping&quot; of an edge: 900 930 20 50 900 930 20 50 Goa l: Maximise the minimum angle in the triangulation
  74. 74. Triangulation of Planar Point Sets Given: Set P of n points in the plane (not all collinear ). A triangulation T(P) of P is a planar subdivision of the convex hull of P into triangles with vertices from P . T(P) is a maximal planar subdivision. For a given point set there are only fin itel y many different triangulations.
  75. 75. Size of Triangulations Theorem : Let P be a set of n points in the plane, not all collinear and let k denote the number of points in P that lie on the boundary of the convex hull for P . Then any trianglation of P has 2n-2-k triangles and 3n-3-k edges. Proof : Let T be triangulation of P , and let m denote the # of triangles of T . Each triangle has 3 edges, and the unbounded face has k edges .  n f = # of faces of t riangulation = m + 1 every edge is incident to exactly 2 faces . Hence, # of edges n e = (3m +k)/2 . Euler ‘s formula : n - n e + n f = 2 . Substituting values of n e and n f , we obtain: m = 2n – 2 – k and n e = 3n – 3 – k .
  76. 76. Angle Vector Let T(P) be a triangulation of P ( set of n points ) . Suppose T(P) has m triangles. Consider the 3m angles of triangles of T(P) , sorted by increasing value . A(T) = { a 1 ..., a 3m } is called angle- vector of T . Triangulations can be sorted in lexicographical order according to A(T). A triangulation T(P) is called angle-optimal if A(T(P))  A(T´(P)) for all triangulations T´ of P .
  77. 77. Illegal Edge a 1 ‘ a 2 ‘ a 4 ‘ a 3 ‘ a 5 ‘ a 6 ‘ P k P j P i Edge flip  The edge p i p j is illegal if  ‘ i Note: Let T be a triangulation with an illegal edge e . Let T´ be the triangulation obtained from T by flipping e . Then, A(T´)  A(T) .  i  Consider a quadrilateral: a 1 a 2 a 6 a 5 a 3 a 4 P j P i
  78. 78. Legal Triangulation Definition : A triangulation T(P) is called a legal triangulation , if T(P) does not contain any illegal edges. Test for illegality Lemma : Let edge p i p j be incident to triangles p i p j p k and p i p j p l , and let C be the circle thru p i , p j and p k . The edge p i p j is illegal iff the point p l lies in the interior of C . Furthermore, if the points p i , p j , p k , p l form a convex quadri- lateral and do not lie on a common circle, then exactly one of p i p j or p k p l is an illegal edge. P i P k P j P l
  79. 79. Test of Illegality Observation: p l lies inside the circle through p i , p j and p k iff p k lies inside the circle through p i , p j , p l . When all four points lie on circle, both p i p j and p k p l are legal. P i P k P j P l P i P k P j P l
  80. 80. Thales Theorem <ul><li>asb   aqb =  apb   arb </li></ul>illegal Lemma: Let C be the circle through the triangle p i , p j , p k and let the point p l be the fourth point of a quadrilateral. The edge p i p j is illegal iff p l lies in the interior of C. a b p q r s p i p j p k p l
  81. 81. Thales Theorem Consider the quadrilateral with p l in the interior of the circle that goes through p i , p j , p k . Claim: The minimum angle does not occur at p k ! (likewise: Minimum angle does not occur at p l ) G oal: Show that p i p j is illegal p i p j p l p k p i p j p l p k
  82. 82. W.l.o.g. a 4 minimal Thales Theorem: Proof a 1 ‘ > a 4 a 2 ‘ > a 2 p i p j p k p l a 1 a 2 a 3 a 4 p i p j p k p l a 1 a 2 a 3 a 4 a 1 ‘ a 2 ‘ a 3 ‘ a 4 ‘ p i p j p k p l a 1 ‘ a 2 ‘ a 3 ‘ a 4 ‘
  83. 83. Circle criterion violated  illegal edge Thales Theorem: Proof a 4 ‘ > a 1 a 3 ‘ > a 3 Hence, min{a i ‘} > min{a i } p i p j p k p l a 1 a 2 a 3 a 4 a 1 ‘ a 2 ‘ a 3 ‘ a 4 ‘
  84. 84. Circle Criterion Definition: A triangulation fulfills the circle criterion if and only if the circumcircle of each triangle of the triangulation does not contain any other point in its interior .
  85. 85. Theorems Theorem: A triangulation T(P) of a set P of points does not contain an illegal edge if and only if nowhere the circle criterion is violated . Theorem: Every triangulation T(P) of a set P of points can be finally transformed into an angle-optimal triangulation in a finite number of steps.
  86. 86. Definition of the Delaunay Triangulation A triangulation T(P) is a Delaunay Triangulation of P, denoted as DT(P), if and only if the circumcircle of any triangle of T does not contain any other point of P in its interior (i.e. T fulfills the circle criterion).
  87. 87. Equivalent Characterisations of the Delaunay Triangulation <ul><li>DT(P) is the straight - line - dual of Voronoi Diagram VD(P) . </li></ul><ul><li>DT(P) is a triangulation of P such that all edges are legal ( local angle - optimal ) . </li></ul><ul><li>DT(P) is a triangulation of P such that for each triangle the circle criterion is fulfilled . </li></ul><ul><li>DT(P) is global angle - optimal triangulation . </li></ul><ul><li>DT(P) is a triangulation of P such that for each edge p i p j ther e is a circle , on wh ich p i and p j lie and which does not contain any other point from P . </li></ul>
  88. 88. Algorithm DT(P) (randomized, incremental) Given: Point set P = {p 1 ..., p n } Initially : Compute triangle (x, y, z) , which includes the points p 1 ..., p n . m z (0,3m) y (3m,0) x (-3m,-3m)
  89. 89. Algorithm DT(P) <ul><li>m = max { |x i |,|y i | } </li></ul><ul><li>T = ((3m, 0), (3m , 3m), (0, 3m)) </li></ul><ul><li>initialize DT(P) as T . </li></ul><ul><li>permutate the points in P random ly . </li></ul><ul><li>for r = 1 to n do </li></ul><ul><li>find the triangle in DT(P), which contains p r ; </li></ul><ul><li> insert new edges in DT(P) to p r ; </li></ul><ul><li> legalize new edges. </li></ul><ul><li>4. remove all edges, which are connected with x, y or z . </li></ul>
  90. 90. Inserting a Point p i p j p r 2 cases : p r is inside a triangle p r is on an edge p i p j p k p r p l p i p j p k p r Legalize (p r ,p i p j ,T): if p i p j is illegal then let p i p j p k be the triangle adjacent to p r p i p j along p i p j . flip p i p j , i.e. replace p i p j by p r p k Legalize (p r , p i p k , T) Legalize (p r , p k p j , T)
  91. 91. Algorithm Delaunay Triangulation Input: A set of p oint s P = {p 1 ..., p n } in general position Output : The Delaunay triangulation DT(P) of P <ul><li>DT(P) = T = (x, y, z) </li></ul><ul><li>for r = 1 to n do </li></ul><ul><li>find a triangle p i p j p k  T , th at contains p r . </li></ul><ul><li>if p r lies in the interior of the triangle p i p j p k </li></ul><ul><li>then split p i p j p k </li></ul><ul><li>Legalize( p r, p i p j ), Legalize( p r, p i p k ), Legalize( p r, p j p k ) </li></ul><ul><li>if p r lies on an edge of p i p j p k (say p i p j ) </li></ul><ul><li>then split p i p j p k and p i p j p l Legalize (p r , p i p l ) , Legalize (p r , p i p k ), Legalize (p r , p j p l ) , Legalize (p r , p j p k ) </li></ul><ul><li>Delete (x, y, z) with all incident edges to P </li></ul>
  92. 92. Correctness Lemma : Every new edge created in the algorithm for constructing DT during the intersection of p r is an edge of the Delaunay graph of   { p 1 ,...,p r } . pq is a Delaunay edge iff there is a (empty) circle, which contains only p and q on the circumference . Proof idea : Shrink a circle which was empty before addition of p r !
  93. 93. Correctness Observation: After insertion of p r , every new edge produced by edge-flips is incident to p r !  Correctness of the algorithm : Consider newly produced edges: p r p r
  94. 94. Edge Flips Edge-flips produce only legal edges. Before inserting p r , circle that goes through p i , p j , p k was empty! Edge- flips produce edges that are always in c ident to p r ! p r p i p j p k
  95. 95. Data Structure for Point Location t 1 t 2 t 4 t 5 t 3 t 6 t 7  Split t 1 p i p j p i p k t 1 t 2 t 3 t 2 t 3 t 4 t 5 t 4 t 6 t 7 t 1 t 2 t 3 t 1 t 2 t 3 t 1 t 2 t 4 t 5 t 3  flip p i p j  flip p i p k
  96. 96. Analysis of the Algorithm Lemma : The expected number of triangles created by the incremental algorithm for constructing DT(P) is atmost 9n + 1 .
  97. 97. Analysis of the Runtime Theorem : The Delaunay triangulation of a set of P of n points in the plane can be computed in O(n log n) expected time, using O(n) expected storage. Proof : Running time without Point Location : Proportional to the number of created triangles = O(n). Point Location : The time to locate the point p r in the current triangulation is linear in the number of nodes of D that we visit.
  98. 98. Relation to Euclidean MST <ul><li>Problem: </li></ul><ul><ul><li>Find a spanning tree on a set P of N points in a plane such that the total length of all the edges of the tree is minimized (Euclidean MST) </li></ul></ul><ul><li>Relation of Delaunay Triangulation </li></ul><ul><ul><li>A Euclidean MST is a sub-graph of a Delaunay Triangulation </li></ul></ul><ul><ul><li>Blindly applying MST finding methods like Kruskal’s or Prim’s on this problem gives O ( m ) where m = n(n-1)/2 . </li></ul></ul><ul><ul><li>If one builds the DT(P) in O ( n log n ) and then does Kruskal’s or Prim’s, one get an O ( n log n ) solution. </li></ul></ul>
  99. 99. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  100. 100. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  101. 101. Geometry and Air Traffic Control » Avoid collisions at all costs. » Start by f inding the two aeroplanes closest to each other, at specific elevations. » During peak times over 5000 planes, per hour, around Frankfurt airspace.
  102. 102. Geometry and Astronomy » Find the two nearest objects in space.
  103. 103. Search Quickly… and Why ? » Find the two nearest objects in space.
  104. 104. Problem Description <ul><li>Input: A set S of n points in the plane. </li></ul><ul><li>Output: The pair of points with the shortest Euclidean distance between them. </li></ul><ul><li>Other applications in fundamental geometric primitive: </li></ul><ul><ul><li>Graphics, computer vision, geographic information systems, molecular modeling </li></ul></ul><ul><ul><li>Special case of nearest neighbour, Euclidean MST, Voronoi </li></ul></ul>
  105. 105. Closest Pair of Points <ul><li>Naïve method: Brute force. </li></ul><ul><ul><li>Check all pair of points p and q with Θ ( n 2 ) comparisons. </li></ul></ul><ul><li>1D version </li></ul><ul><ul><li>Simple if all points are on a single line. </li></ul></ul><ul><ul><li>Run time O ( n log n ) </li></ul></ul><ul><li>Key to reducing quadratic runtime of the na ï ve method: </li></ul><ul><li>Simply don´t visit each point n times. </li></ul>
  106. 106. Algorithm: DAC – Divide <ul><li>Sort S in ascending order of x -coordinates. </li></ul><ul><li>Find the median line L , so that we have ½ n points in S L and ½ n points S R . </li></ul>S L S R
  107. 107. Algorithm: DAC – Conquer <ul><li>Recursively, find the closest pair in S L and S R . </li></ul>S L S R
  108. 108. Algorithm: DAC – Merge (Strip-Margins) <ul><li>Assuming that distance <  S = min(  SL ,  SR ). </li></ul><ul><li>Observation: Only need to consider the points within  S of line L . </li></ul>S L S R  S  S = min(12,21)
  109. 109. Handling Merge <ul><li>Sort points in 2  S -strip in ascending y -coordinate order. </li></ul><ul><li>( First observation ) Only check those points within 11 positions in sorted list. </li></ul>S L S R  S  S = min(12,21)
  110. 110. Comparing Efficiently <ul><li>Definition: Let s i be the point in the 2  S -strip with the i th smallest coordinate. </li></ul><ul><li>Claim: If | i - j |  12, then the distance between s i and s j is at least  S . </li></ul><ul><li>Proof: </li></ul><ul><li>The points s i and s j cannot lie in same ½  S -by- ½  S box. </li></ul><ul><li>s i and s j are at least 2 rows apart, and have distance  2(½  S ). </li></ul><ul><li>Fact: </li></ul><ul><li>The above still holds if we replace 12 with 7. </li></ul> S  S
  111. 111. Closest Pair: DAC Algorithm <ul><li>Algorithm: Closest-Pair ( S = { p 1 , …, p n } ) </li></ul>Sort all n points in ascending x -coordinate order Compute the median line L , and divide S into S L and S R Set  SL  Closest-Pair ( S L ) Set  SR  Closest-Pair ( S R ) Set  S  min(  SL ,  SR ) Delete all points further than  S  from separation line L Sort remaining points in ascending y -coordinate order Scan points in y -order and compare distance between each point and next 7 neighbours. Update  S if new shorter distance is found. Return  S
  112. 112. Closest Pair: DAC Analysis <ul><li>Run time: </li></ul><ul><li>T ( N )  2 T ( N /2) + O ( N log N )  T ( N ) = O ( N log 2 N ) </li></ul><ul><li>Can we achieve a better run time? </li></ul><ul><li>Yes. Don’t sort points in strip from scratch each time. </li></ul><ul><li>Each recursive step returns two lists: all points sorted by y -coordinate, and all points sorted by x -coordinate. </li></ul><ul><li>Sort by merging two pre-sorted list. </li></ul><ul><li>T ( N )  2 T ( N /2) + O ( N )  T ( N ) = O ( N log N ) </li></ul><ul><li>Space: </li></ul><ul><li>O ( n ) </li></ul>
  113. 113. Algorithm: Scan-Line <ul><li>Sort S in ascending order of x -coordinates. </li></ul><ul><li>Place sorted points p 1 , …, p n in the event-queue. </li></ul><ul><li>Initialise   distance( p 1 , p 2 ). </li></ul><ul><li>Start scanning from p 3 . </li></ul>» Event-points? » Status structure?
  114. 114. The Status-Structure <ul><li>Maintain the status-structure (  -slab): </li></ul><ul><ul><li>Insert the new event-point p i . </li></ul></ul><ul><ul><li>Remove all points that are greater than  distance to the left of the current event-point p i . </li></ul></ul><ul><ul><li>All points in the status structure are maintained in ascending y -coordinate order. </li></ul></ul>
  115. 115. The Status-Structure <ul><li>Maintain the status-structure (  -slab): </li></ul><ul><ul><li>Insert the new event-point p i . </li></ul></ul><ul><ul><li>Remove all points that are greater than  distance to the left of the current event-point p i . </li></ul></ul><ul><ul><li>All points in the status structure are maintained in ascending y -coordinate order. </li></ul></ul><ul><ul><li>Perform the ‘ Efficient Comparison ’, as described earlier, BUT only between the new event point p i and at most 7 other nearest points to p i . </li></ul></ul><ul><ul><li>Update  if a shorter distance is found. </li></ul></ul>
  116. 116. Closest Pair: Scan-Line Analysis <ul><li>Invariant: </li></ul><ul><li>Whenever an event-point p i has been handled, then  is the minimum distance between any pair of points encountered from p 1 up to p i . </li></ul><ul><li>Run time: </li></ul><ul><li>O ( n log n ) </li></ul><ul><li>Space: </li></ul><ul><li>O ( n ) </li></ul>
  117. 117. Related Problems <ul><li>Nearest neighbour query: </li></ul><ul><ul><li>Given a set S of n points, and a query point q , determine which s  S is closest to q . </li></ul></ul><ul><ul><li>Brute force: O ( n ) </li></ul></ul><ul><ul><li>Goal: O ( n log n ) pre-processing, O (log n ) per query. </li></ul></ul><ul><li>Voronoi region, VR ( S ): </li></ul><ul><ul><li>A set of points closest to a given point. </li></ul></ul><ul><li>Voronoi diagram, VD ( S ): </li></ul><ul><ul><li>Planar subdivision deliniating Voronoi regions. </li></ul></ul><ul><li>Delaunay Triangulation (the dual of VD ( S )). </li></ul>
  118. 118. What will be covered? <ul><li>Mainly popular static problems: </li></ul><ul><ul><li>Point inside polygon </li></ul></ul><ul><ul><li>Convex hull </li></ul></ul><ul><ul><li>Line segment intersection </li></ul></ul><ul><ul><li>Delaunay triangulation </li></ul></ul><ul><ul><li>Closest pair of points </li></ul></ul>
  119. 119. Acknowledgment <ul><li>Slides prepared mainly from the materials of Prof. Dr. Thomas Ottman </li></ul>

×