1 / 28

Identifying and sorting jordan sequences

Identifying and sorting jordan sequences. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. Jordan curve. Jordan curve in the plane : A continous curve that does not intersect itself. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.

jcherie
Download Presentation

Identifying and sorting jordan sequences

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Identifying and sorting jordan sequences

  2. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself

  3. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Jordan sequence The sequence x1,x2,.....,xn of the intersection points of a jordan curve C with the x-axis in the order in which they occur on C. 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19

  4. Our problem An efficient algorithm which would recognize and sort a jordan sequence.

  5. A special case: sort the intersections of an n-sided simple polygon with a line.

  6. Application: Polygon clipping Return the intersection of a polygon with a rectangular window (a collection of polygons)

  7. Polygon clipping Return the intersection of a polygon with a rectangular window (a collection of polygons)

  8. Polygon clipping algorithm

  9. You find the intersections by the order they occur on the polygon. But you also need them by the order they occur on the rectangle

  10. Polygon triangulation Useful for triangulating simple polygons.

  11. Assume to simplify presentation Curve nowhere tangent to the x-axis. Curve start below the x-axis (if not reflect)

  12. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Nested parenthesis Each pair {x2i-1 ,x2i} for i = 1,....,n/2 corresponds to part of C going from the x-axis up and back to the x-axis. 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19

  13. Nested parenthesis (cont) The sequence is a jordan sequence iff different pairs {x2i-1 ,x2i} {x2j-1 ,x2j} cannot cross Cross: either or

  14. Upper and lower trees The parent of {x2i-1 ,x2i} is the “immediate” enclosing pair. This defines a forest . Add {-, } to make it a tree.

  15. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Upper and lower trees (example) -  1 6 7 12 13 21 14 17 2 3 4 5 8 9 10 11 18 20 15 16 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19

  16. The algorithm The algorithm processes x1,x2,.....,xn one at a time building the upper tree, the lower tree, and a list of the points in sorted order. Initialization: Make {-, } the only pair in both trees. Initialize the sorted list to be {-, x1, } For i = 2,....n process xi as follows Suppose i is even, i.e. {xi-1 , xi} is to be added to the upper tree Assume xi-1 < xi (otherwise it is symmetric)

  17. The algorithm (cont) Find the point x that follows xi-1 in the sorted list. Find the pair {xj-1 , xj} in the upper tree such that x  {xj-1 , xj} Let {lj , rj } = {xj-1 , xj} Apply one of the following 4 cases Case A: lj < xi-1 < rj < xi lj xi-1 rj xi Stop, this is not a jordan sequence

  18. The algorithm (cont) Case B: lj < xi-1 < xi < rj lj xi-1 xi rj Make {xi-1 , xi} the new last child of {xj-1 , xj}. Insert xi after xi-1 in the sorted list

  19. The algorithm (cont) Case C: xi-1 < xi < lj xi-1 xi lj rj Insert {xi-1 , xi} into the list of siblings of {xj-1 , xj} just before {xj-1 , xj} Insert xi after xi-1 in the sorted list

  20. lk xi rk The algorithm (cont) Case D: xi-1 < lj < xi xi-1 lj rj In the list of siblings of {xj-1 , xj} find the last pair {xk-1 , xk} such that lk < xi If rk > xi then it is not a jordan sequence.

  21. The algorithm (cont) Case D: xi-1 < lj < xi lp xi-1 lj rj lk rk rp xi Otherwise if {xk-1 , xk} is the last child of its parent pair {xp-1 , xp} and rp < xi it is not a jordan sequence.

  22. The algorithm (cont) Case D: xi-1 < lj < xi lp xi-1 lj rj lk rk xi rp Remove from the list of siblings of {xj-1 , xj} the sublist from {xj-1 , xj} to {xk-1 , xk} (inclusive) and replace it by {xi-1 , xi}. Make the removed sublist the list of children of {xi-1 , xi}. Insert xi after rk into the sorted list.

  23. The algorithm (cont) If i is odd we work similarly with the lower tree.

  24. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 6 7 12 13 21 19 20 17 18 15 16 2 3 4 5 The algorithm (example) 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 -  - 

  25. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 6 7 12 13 21 2 3 4 5 The algorithm (example) 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 -  -  14 18.5 19 20 17 18 15 16

  26. Representation The sorted list of processed numbers is a doubly linked list. Each list of siblings in the upper or lower trees is represented by a homogenous finger search tree. -  1 6 7 12 13 21 14 17 2 3 4 5 8 9 10 11 18 20 15 16

  27. Analysis Inserting a pair before or after some other pair takes O(1) time. Finding and removing a sublist of d pairs from a list of s pairs takes O(1 + log(min{d,s-d})) We perform at most n/2 operations of the form “remove a sublist/insert a pair” each costs O(1 + log(min{d,s-d} )) for some 1  d  s if it operates on a list of length s. What is the total time ?

  28. Analysis (Cont) Assume all elements are there to begin with. This would just make the split operations more expensive. Charge the split evenly to the items in the smaller part, if d is the length of the smaller part then each element is charged log(d)/d The total charge per element is at most log(x1)/x1 + log(x2)/(x2) + … log(xk)/xk The xi decrease exponentially : xi≤ xi-1/2 Therefore the sum is at most Σ k/2k = O(1)

More Related