Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Identifying and sorting jordan sequences. 2 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself 123456789101112131415161718192021.

Similar presentations


Presentation on theme: "1 Identifying and sorting jordan sequences. 2 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself 123456789101112131415161718192021."— Presentation transcript:

1 1 Identifying and sorting jordan sequences

2 2 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself 123456789101112131415161718192021

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

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

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

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

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

8 8 Polygon clipping algorithm

9 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 10 Polygon triangulation Useful for triangulating simple polygons.

11 11 Applications (cont) Computational geography: Given the sequence of intersections of two jordan curves in the order in which they occur on one of the curves sort them in the order in which they occur on the other curve.

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

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

14 14 Nested parenthesis (cont) The sequence is a jordan sequence iff different pairs {x 2i-1,x 2i } {x 2j-1,x 2j } cannot cross Cross: either or

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

16 16 Upper and lower trees (example) 123456789101112131415161718192021 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 -- 16 7121321 234589 1011 1417 1516 1820

17 17 The algorithm The algorithm processes x 1,x 2,.....,x n 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 {- , x 1,  } For i = 2,....n process x i as follows Suppose i is even, i.e. {x i-1, x i } is to be added to the upper tree Assume x i-1 < x i (otherwise it is symmetric)

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

19 19 The algorithm (cont) Case B: l j < x i-1 < x i < r j l j r j x i-1 xixi Make {x i-1, x i } the new last child of {x j-1, x j }. Insert x i after x i-1 in the sorted list

20 20 The algorithm (cont) Case C: x i-1 < x i < l j l j r j x i-1 xixi Insert {x i-1, x i } into the list of siblings of {x j-1, x j } just before {x j-1, x j } Insert x i after x i-1 in the sorted list

21 21 The algorithm (cont) Case D: x i-1 < l j < x i l j r j x i-1 In the list of siblings of {x j-1, x j } find the last pair {x k-1, x k } such that l k < x i If r k > x i then it is not a jordan sequence. xixi l k r k

22 22 The algorithm (cont) Case D: x i-1 < l j < x i l j r j x i-1 Otherwise if {x k-1, x k } is the last child of its parent pair {x p-1, x p } and r p < x i it is not a jordan sequence. xixi l k r k r p l p

23 23 The algorithm (cont) Case D: x i-1 < l j < x i l j r j x i-1 Remove from the list of siblings of {x j-1, x j } the sublist from {x j-1, x j } to {x k-1, x k } (inclusive) and replace it by {x i-1, x i }. Make the removed sublist the list of children of {x i-1, x i }. Insert x i after r k into the sorted list. xixi l k r k r p l p

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

25 25 The algorithm (example) 123456789101112131415161718192021 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 -- -- 16712 1321 2345 1718 1516 1920

26 26 The algorithm (example) 123456789101112131415161718192021 6, 1, 21, 13, 12, 7, 5, 4, 3, 2, 20, 18, 17, 14, 11, 10, 9, 8, 15, 16, 19 -- -- 16712 1321 2345 1718 1516 19201418.5

27 27 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. -- 16 7121321 234589 1011 1417 1516 1820

28 28 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 ?

29 29 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(x 1 )/x 1 + log(x 2 )/(x 2 ) + … log(x k )/x k The x i decrease exponentially : x i ≤ x i-1 /2 Therefore the sum is at most Σ k/2 k = O(1)

30 30 Analysis Let T(p,s) be the maximum time it takes to perform p such operations on an initial list of size s. Then T(p,s) = 0 if p = 0 Max { T(i, d+1) + T(p-i-1, s-d+1) + O(1 + log(min{d,s-d} + 1)) } 0  i < p 0  d  s We are interested in 2T(  n/2 ,1) = O(n) T(p,s) = O(p+s)


Download ppt "1 Identifying and sorting jordan sequences. 2 Jordan curve Jordan curve in the plane: A continous curve that does not intersect itself 123456789101112131415161718192021."

Similar presentations


Ads by Google