computational geometry
play

Computational Geometry Part 2: Line Sweep, Convex Hulls Lucca - PowerPoint PPT Presentation

Computational Geometry Part 2: Line Sweep, Convex Hulls Lucca Siaudzionis and Jack Spalding-Jamieson 2020/02/27 University of British Columbia Announcements A3 is due Sundayyyyy! Project topics are due Tuesday! Presentation dates


  1. Computational Geometry Part 2: Line Sweep, Convex Hulls Lucca Siaudzionis and Jack Spalding-Jamieson 2020/02/27 University of British Columbia

  2. Announcements • A3 is due Sundayyyyy! • Project topics are due Tuesday! • Presentation dates will be on March 31st and April 2nd . • If you can’t present in one of those two days, let us know by March 4th so we can schedule you on the other (with a decent reason). • Otherwise, dates will be randomly assigned. • Extra office hours tomorrow from 2-4PM in ICCSX237. 1

  3. Discussion Problem: Remember How to do Line Sweep? Jack is constantly busy with meetings that take up all his time. Many of his meetings even overlap! Given a list of 1 ≤ n ≤ 10 6 meetings along with their start and end times, find out how much time Jack spends overwhelmed with meetings. 2

  4. Discussion Problem: Remember How to do Line Sweep? – Insight We can process the “events” (start and end times) in increasing order (the “ x ”-coordinate in Line Sweep), keeping track of how many intervals are currently under the sweep line. 3

  5. Line sweep: General Plan The general method for solving sweep problems: • Identify important “events” that occur as we move from left to right. • Keep track of some auxiliary data structure that lets us • find the answer, and • update efficiently at each event. 4

  6. Line Sweep: Pachinko Given N ≤ 10 5 non-intersecting, non-horizontal line segment obstacles, where does the pinball end up? 5

  7. Line Sweep: Pachinko We only need to know for each segment, which “next segment” the pinball will fall onto. We’ll find these by sweeping from left to right. 6

  8. Line Sweep: Pachinko We only need to know for each segment, which “next segment” the pinball will fall onto. We’ll find these by sweeping from left to right. 7

  9. Line Sweep: Pachinko We only need to know for each segment, which “next segment” the pinball will fall onto. We’ll find these by sweeping from left to right. 8

  10. Line Sweep: Pachinko Data structure: A set of lines, sorted by their order on the y -axis. Events: The line segment endpoints. Actions: • Left endpoint: Insert line into the set • Right endpoint: Remove line from the set • Lower endpoint of segment: Query for the next line below the point 9

  11. Convex Sets A set S is convex ⇔ ∀ x , y ∈ S , 0 ≤ λ ≤ 1 , λ x + (1 − λ ) y ∈ S ⇔ the line segment x → y is inside the set Figure 1: In a convex set, the line segment between any 2 points lies in a set 10

  12. Convex Hulls: Definition A convex hull of a set is the smallest convex set containing the set. Figure 2: Some sets and their convex hulls Why do we care about convex hulls? They give us nice convex polygons, which we can optimize over easier. 11

  13. Convex Hulls: Finite Point Sets If we have a finite set of points, we define the following about a point p and the convex hull H : • p may be in the interior, i.e. p is not found on H at all. • p may be a vertex of the convex hull, i.e. removing p would make the convex hull smaller. • p could lie on an edge in the convex hull. When finding a convex hull, we need to know which of these sets we’re looking for (just the vertices? or all the points on the convex hull). 12

  14. Convex Hulls: Applications Convex Hulls can be used for many real-world applications, such as: • In game programming, they can be used to speed up collision-detection, similarly to bounding-boxes. • Can be used to find the shortest paths around physical objects (remember the circle problem from last class?). • And much more... 13

  15. Convex Hulls: Gift Wrapping How do we find the convex hull of a finite point-set with n points? 14

  16. Convex Hulls: Gift Wrapping How do we find the convex hull of a finite point-set with n points? We can use the gift wrapping algorithm : • Start at some point that is guaranteed to be a vertex in the convex hull, e.g. the leftmost point (break ties by height). • Look at all of the other points, and choose the one that maximizes the angle with the line segment pointing downwards from our original point. • The point chosen is the next point in the convex hull. • Do this iteratively until we hit a point already added, but with the most recent line segment added to the convex hull. Overall runtime: O ( n 2 ) 14

  17. Convex Hulls: Gift Wrapping Example (1) 15

  18. Convex Hulls: Gift Wrapping Example (2) 16

  19. Convex Hulls: Gift Wrapping Example (3) 17

  20. Convex Hulls: Gift Wrapping Example (4) 18

  21. Convex Hulls: Gift Wrapping Example (5) 19

  22. Convex Hulls: Gift Wrapping Example (6) 20

  23. Convex Hulls: Gift Wrapping Example (7) 21

  24. Convex Hulls: Gift Wrapping Example (8) 22

  25. Convex Hulls: Gift Wrapping Example (9) 23

  26. Convex Hulls: Gift Wrapping Example (10) 24

  27. Convex Hulls (Aside): Gift Wrapping – Output Sensitivity Although the runtime of gift wrapping is in fact a tight Θ( n 2 ), we can actually give a better bound! This is using something called output sensitivity : If we know that there will be at most h < n points on the eventual convex hull, we can actually bound the algorithm with complexity O ( nh ). 25

  28. Convex Hulls: Faster Algorithms Are there faster algorithms for solving this? 26

  29. Convex Hulls: Faster Algorithms Are there faster algorithms for solving this? Yes. Lots. No less than eight: • Graham Scan ( O ( n log n )) • Monotone Chain/Andrew’s Algorithm ( O ( n log n )) • Quickhull ( O ( n log n ) average case) • Divide & Conquer via axis split ( O ( n log n )), extendable to 3D! • Divide & Conquer with arbitrary merge and rotating calipers ( O ( n log n )) • Kallay’s incremental algorithm ( O ( n log n )) • Kirkpatrick-Seidel Algorithm ( O ( n log h )), aka the ”ultimate planar convex hull algorithm” • Chan’s Algorithm ( O ( n log h )) We’re going to talk about Monotone Chain/Andrew’s Algorithm, although the algorithm is very similar to Graham’s algorithm. 26

  30. Monotone Chain Algorithm Step 1: scan from left to right, “wrap” around the top Step 2: scan from right to left, “wrap” around the bottom. Figure 3: Upper and lower hulls built by monotone chain algorithm 27

  31. Monotone Chain Algorithm 28

  32. Monotone Chain Algorithm 28

  33. Monotone Chain Algorithm 28

  34. Monotone Chain Algorithm 28

  35. Monotone Chain Algorithm 28

  36. Monotone Chain Algorithm 28

  37. Monotone Chain Algorithm 28

  38. Monotone Chain Algorithm 28

  39. Monotone Chain Algorithm 28

  40. Monotone Chain Algorithm 28

  41. Monotone Chain Algorithm 28

  42. Monotone Chain Algorithm 28

  43. Monotone Chain Algorithm 28

  44. Monotone Chain Algorithm 28

  45. Monotone Chain Algorithm 28

  46. Monotone Chain Algorithm 28

  47. Monotone Chain Algorithm 28

  48. Monotone Chain Algorithm 28

  49. Monotone Chain Algorithm 28

  50. Monotone Chain Algorithm Algorithm summary • Sort all points by x -coordinate • Start from leftmost point (i.e. smallest x -coordinate) • If there are ties, you can take the uppermost one (largest y -coordinate) • Iteratively add points into the hull • If adding a point causes CCW turn, pop points from hull until this is no longer the case before adding! • Repeat the above steps from right to left. 29

  51. Monotone Chain Algorithm Edge cases • Convex hull of 1, 2, 3 points • Collinear points 30

  52. Monotone Chain Algorithm Time complexity analysis • Sort all points by x -coordinate: O ( n log n ) • Each point is added and removed at most once: O ( n ) ⇒ Time complexity: O ( n log n ) Without looking at output sensitivity, can we do better? 31

  53. Monotone Chain Algorithm Time complexity analysis • Sort all points by x -coordinate: O ( n log n ) • Each point is added and removed at most once: O ( n ) ⇒ Time complexity: O ( n log n ) Without looking at output sensitivity, can we do better? With angle-based comparison, we can use the sorting lower bound: Arrange n points on a circle ⇒ equivalent to sorting in some sense, Ω( n log n ). 31

  54. Discussion Problem: Visibility Input : A point-set D of 1 ≤ n ≤ 10 5 key-points representing some convex geometric object, guaranteed to include all boundary points. Additionally, there are 1 ≤ q ≤ 10 5 queries. For each query, a point p is provided, guaranteed to be outside the boundary of the object. Output : For each query, output the angles over which a camera positioned at point p would not be able to see past the object. P 32

  55. Discussion Problem: Visibility – Insight (1) Observation 1 : The solution for each query lies on the convex hull. Observation 2 : Pick an arbitrary point on the hull, draw a line through, then one extremum is on each side of the line. P 33

  56. Discussion Problem: Visibility – Insight (2) Binary search to find start/end vertices on each half of the hull, and then binary search on each half of the hull for when P → p i → p i +1 changes from CCW to CW (or vice versa). Time complexity: O ( N log N + Q log N ) This problem has many applications, including game programming, graphics, and more broad computational geometry problems (such as euclidean shortest path problems). 34

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend