computing convex hull in 2d
play

Computing Convex Hull (in 2D) Computational Geometry Convex hull - PowerPoint PPT Presentation

Yazd Univ. Computing Convex Hull (in 2D) Computational Geometry Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness 1393-1 Other algorithms Higher dimensions 1 / 20 Convex Set Definition: Yazd


  1. Yazd Univ. Computing Convex Hull (in 2D) Computational Geometry Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness 1393-1 Other algorithms Higher dimensions 1 / 20

  2. Convex Set Definition: Yazd Univ. A subset S of the plane is called convex if and only if for any pair of points p, q ∈ S , the line segment pq is Computational Geometry completely contained in S . Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness Convex Hull: Other algorithms Higher dimensions The convex hull CH ( S ) of a set S is the smallest convex set that contains S . To be more precise, it is the intersection of all convex sets that contain S . 2 / 20

  3. Convex Set Definition: Yazd Univ. A subset S of the plane is called convex if and only if for any pair of points p, q ∈ S , the line segment pq is Computational completely contained in S . Geometry q q Convex hull Definition Geometry of problem 1st algorithm pq pq 2nd algorithm Proof of correctness Other algorithms p p Higher dimensions convex not convex Convex Hull: The convex hull CH ( S ) of a set S is the smallest convex set that contains S . To be more precise, it is the intersection of all convex sets that contain S . 2 / 20

  4. Convex Set Definition: Yazd Univ. A subset S of the plane is called convex if and only if for any pair of points p, q ∈ S , the line segment pq is Computational Geometry completely contained in S . Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness Convex Hull: Other algorithms Higher dimensions The convex hull CH ( S ) of a set S is the smallest convex set that contains S . To be more precise, it is the intersection of all convex sets that contain S . 2 / 20

  5. Computing CH: Observation: Yazd Univ. It is the unique convex polygon whose vertices are points from P and that contains all points of P . Computational Geometry Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness Other algorithms Higher dimensions 3 / 20

  6. Computing CH: Observation: Yazd Univ. It is the unique convex polygon whose vertices are points from P and that contains all points of P . Computational Geometry Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness Other algorithms Higher dimensions 3 / 20

  7. Computing CH: Problem: Yazd Univ. Given a set P = { p 1 , p 2 , . . . , p n } of points in the plane, compute a list that contains those points from P that are Computational Geometry the vertices of CH ( P ) , listed in clockwise order. Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness Other algorithms Higher dimensions 4 / 20

  8. Computing CH: Problem: Yazd Univ. Given a set P = { p 1 , p 2 , . . . , p n } of points in the plane, compute a list that contains those points from P that are Computational Geometry the vertices of CH ( P ) , listed in clockwise order. Convex hull p 9 p 4 Definition Input= set of points Geometry of problem p 1 1st algorithm p 7 p 1 , p 2 , p 3 , p 4 , p 5 , p 6 , p 7 , p 8 , p 9 2nd algorithm Proof of correctness p 2 Output= representation of the convex hull: p 3 Other algorithms p 6 Higher dimensions p 5 p 4 , p 5 , p 8 , p 2 , p 9 p 8 4 / 20

  9. Geometry of the problem Property: If we direct the line through p and q such that CH ( P ) lies Yazd Univ. to the right, then all the points of P must lie to the right of Computational this line. The reverse is also true: if all points of P \ { p, q } Geometry lie to the right of the directed line through p and q , then pq is an edge of CH ( P ) . Convex hull Definition Geometry of problem p 1st algorithm q 2nd algorithm Proof of correctness Other algorithms Higher dimensions 5 / 20

  10. First algorithm Algorithm S LOW C ONVEX H ULL ( P ) Input: A set P of points in the plane. Output: L = The vertices of CH ( P ) in clockwise order. Yazd Univ. 1. E ← ∅ . Computational for all ordered pairs ( p, q ) ∈ P × P with p � = q 2. Geometry 3. valid ← true for all points r ∈ P not equal to p or q 4. Convex hull → 5. if r lies to the left Definition pq Geometry of problem 6. then valid ← false . 1st algorithm 2nd algorithm → 7. if valid then Add pq to E . Proof of correctness Other algorithms 8. From the set E of edges construct vertices of CH ( P ) , Higher dimensions sorted in clockwise order. Clarify: How do we test whether a point lies to the left or to 1 the right of a directed line? (See Exercise 1.4) How can we construct L from E ? 2 6 / 20

  11. First algorithm Algorithm S LOW C ONVEX H ULL ( P ) Input: A set P of points in the plane. Output: L = The vertices of CH ( P ) in clockwise order. Yazd Univ. 1. E ← ∅ . Computational for all ordered pairs ( p, q ) ∈ P × P with p � = q 2. Geometry 3. valid ← true for all points r ∈ P not equal to p or q 4. Convex hull → 5. if r lies to the left Definition pq Geometry of problem 6. then valid ← false . 1st algorithm 2nd algorithm → 7. if valid then Add pq to E . Proof of correctness Other algorithms 8. From the set E of edges construct vertices of CH ( P ) , Higher dimensions sorted in clockwise order. Clarify: How do we test whether a point lies to the left or to 1 the right of a directed line? (See Exercise 1.4) How can we construct L from E ? 2 6 / 20

  12. Computing L : All edges are directed. remove an arbitrary edge e 1 from Yazd Univ. E. Put the origin of e 1 and the destination in L . Computational Geometry destination of e 1 Find the edge e 2 in E whose =origin of e 2 origin is the destination of e 1 , Convex hull remove it from E, and append its Definition e 1 Geometry of problem destination to L . 1st algorithm 2nd algorithm e 2 Proof of correctness Next, find the edge e 3 whose Other algorithms origin of e 1 Higher dimensions origin is the destination of e 2 , remove it from E, and append its destination to L . And so on. Time Complexity: O ( n 2 ) 7 / 20

  13. Complexity of the algorithm Algorithm S LOW C ONVEX H ULL ( P ) Input: A set P of points in the plane. Output: L = The vertices of CH ( P ) in clockwise order. Yazd Univ. 1. E ← ∅ . Computational for all ordered pairs ( p, q ) ∈ P × P with p � = q 2. Geometry 3. valid ← true for all points r ∈ P not equal to p or q 4. Convex hull → Definition 5. if r lies to the left pq Geometry of problem 1st algorithm 6. then valid ← false . 2nd algorithm → Proof of correctness 7. if valid then Add pq to E . Other algorithms Higher dimensions 8. From the set E of edges construct vertices of CH ( P ) , sorted in clockwise order. Running time: O ( n 3 ) + O ( n 2 ) = O ( n 3 ) . 8 / 20

  14. Complexity of the algorithm Algorithm S LOW C ONVEX H ULL ( P ) Input: A set P of points in the plane. Output: L = The vertices of CH ( P ) in clockwise order. Yazd Univ. 1. E ← ∅ . Computational for all ordered pairs ( p, q ) ∈ P × P with p � = q 2. Geometry 3. valid ← true for all points r ∈ P not equal to p or q 4. Convex hull → Definition 5. if r lies to the left pq Geometry of problem 1st algorithm 6. then valid ← false . 2nd algorithm → Proof of correctness 7. if valid then Add pq to E . Other algorithms Higher dimensions 8. From the set E of edges construct vertices of CH ( P ) , sorted in clockwise order. Running time: O ( n 3 ) + O ( n 2 ) = O ( n 3 ) . 8 / 20

  15. Degenerate case (or Degeneracy) Degenerate Case: Yazd Univ. A point r does not always lie to the right or to the left of the line through p and q , it can also happen that it lies on Computational Geometry this line. What should we do then? Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness Other algorithms Higher dimensions Solution: A directed edge − → pq is an edge of CH ( P ) if and only if all other points r ∈ P lie either strictly to the right of the directed line through p and q , or they lie on the open line segment pq . 9 / 20

  16. Degenerate case (or Degeneracy) Degenerate Case: Yazd Univ. A point r does not always lie to the right or to the left of the line through p and q , it can also happen that it lies on Computational Geometry this line. What should we do then? Convex hull Definition Geometry of problem 1st algorithm 2nd algorithm Proof of correctness Other algorithms Higher dimensions Solution: A directed edge − → pq is an edge of CH ( P ) if and only if all other points r ∈ P lie either strictly to the right of the directed line through p and q , or they lie on the open line segment pq . 9 / 20

  17. Robustness: Robustness: Yazd Univ. If the points are given in floating point coordinates and the computations are done using floating point arithmetic, Computational Geometry then there will be rounding errors that may distort the outcome of tests. Convex hull Definition Geometry of problem 1st algorithm q q 2nd algorithm Proof of correctness Other algorithms r Higher dimensions r p p This algorithm is not robust! 10 / 20

  18. Robustness: Robustness: Yazd Univ. If the points are given in floating point coordinates and the computations are done using floating point arithmetic, Computational Geometry then there will be rounding errors that may distort the outcome of tests. Convex hull Definition Geometry of problem 1st algorithm q q 2nd algorithm Proof of correctness Other algorithms r Higher dimensions r p p This algorithm is not robust! 10 / 20

Recommend


More recommend