Presentation is loading. Please wait.

Presentation is loading. Please wait.

Line Segment Intersection Computational Geometry, WS 2007/08 Lecture 3 – Supplementary Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut.

Similar presentations


Presentation on theme: "Line Segment Intersection Computational Geometry, WS 2007/08 Lecture 3 – Supplementary Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut."— Presentation transcript:

1 Line Segment Intersection Computational Geometry, WS 2007/08 Lecture 3 – Supplementary Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften Albert-Ludwigs-Universität Freiburg

2 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann2 Line Segment Intersection: Additions Implementation of the event queue by a heap: The complexity of heap construction Iso-oriented line segments Intersection counting Line segment intersection by Divide & Conquer Polygon intersection

3 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann3 Heaps Definition. A sequence F = (k 1, k 2,..., k n ) of keys is a (Max-) Heap, iff for all i  {1, 2, …, n/2} : k i ≥ k 2i und k i ≥ k 2i+1. This requirement for an array can be interpreted as a condition on a complete binary tree: Level i has 2 i nodes (except, eventually, the last level) Node i has node 2i as ist left and node 2i + 1 as its right successor and node  i/2  as ist predecessor (if they exist)

4 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann4 Heap Construction Level, #nodes, #comp./exchanges k levels, total # of nodes = 2 k+1 -1

5 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann5 Heap Construction Heap construction by iterative trickling down: ² k = 32 k nodes Total number of nodes: n = 2 k Total number of key comparisons and exchanges:.

6 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann6 Complexity of Heap Construction Total complexity = 2 0 2k (k-1) (k-2) + … + 2 (k-1 ) 2 = 2 S(k), where S(k) = 2 0 k (k-1) (k-2) + … + 2 (k-1) 1 = 2 (n – k – 1) = O(n)

7 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann7 Intersections of iso-oriented Line Segments Report all pairs of intersecting segments Count the number of intersecting segments

8 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann8 Iso-oriented Line Segments Report all pairs of intersecting segments: A sweep-line algorithm can solve this problem in optimal time O(n log n + k) and space O(n), k = # of intersections!

9 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann9 Iso-oriented Line Segments Count all pairs of intersecting segments: A sweep-line algorithm can solve this problem in optimal time O(n log n) and space O(n)!

10 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann10 A Divide and Conquer Algorithm Report all pairs of intersecting segments

11 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann11 How to divide the input set A separate representation of segments allows to divide the input set. A B C D E A. B. C. D. E..A.D.B.C.E

12 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann12 ReportCuts(S) Input:Set S of vertical segments and endpoints of horizontal segments. Output: All pairs of intersecting vertical segments and those horizontal segments which are represented by at least one endpoint in S. 1. Divide if |S| > 1 then divide S by a vertical line G into two sets S 1 (to the left of G) and S 2 (to the right of G) of equal size else S contains no intersections

13 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann13 ReportCuts A B C D E A D B C E S S1S1 S2S2 1. Divide 2. Conquer ReportCuts(S 1 ); ReportCuts(S 2 )

14 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann14 ReportCuts 3. Merge: ??? Different possibilities for intersections of a horizontal segment in S 1 Case 1: both endpoints in S 1 h S1S1 S2S2

15 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann15 ReportCuts Case 2: only one endpoint of h in S1 2 a) right endpoint in S1 h S1S1 S2S2

16 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann16 ReportCuts 2 b) left endpoint of h in S 1 h S1S1 right endpoint in S 2 h S1S1 right endpoint not in S 2 S2S2 S2S2

17 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann17 ReportCuts(S) 3. Merge: Report intersections between vertical segments in S 2 and those horizontal segments in S 1, for which the left endpoint is in S 1 and the right endpoint is neither in S 1 nor in S 2 Analogously for S 1 S1S1 S2S2

18 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann18 Implemention Set S L(S): y-coordinats of all left endpoints in S which have no right partner in S R(S): y-coordinats of all right endpoints in S which have no left partner in S V(S): y-intervals of vertical segments in S

19 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann19 Base Cases S contains only one element s Case 1: s = (x,y) is left endpoint L(S) = {y} R(S) =  V(S) =  Case 2: s = (x,y) is right endpoint L (S)=  R(S) = {y} V(S) =  Case 3: s = (x,y 1,y 2 ) is vertical segment L(S) =  R(S) =  V(S) = {[y 1,y 2 ]}

20 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann20 Merge Step Assume L(S i ), R(S i ), V(S i ) i=1,2 are known and S = S 1  S 2 L(S) = R(S) = V(S) = L,R: sorted according to increasing y-coordinats linked lists V: sorted according to increasing lower endpoints linked list

21 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann21 Reporting of Intersections V(S 2 ) h3h3 h2h2 h1h1 L(S 1 )

22 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann22 Runtime Input (vertical segments, left/right endpoints of horizontal segments) has to be sorted initially and is stored in an array. Divide-and-Conquer: T(n) = 2T(n/2) + an + output-size T(1) = O(1) O(n log n + k) k = #intersections

23 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann23 Polygon Intersection by Line Sweep A B C D E F G

24 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann24 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q Sweep direction

25 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann25 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D Status-structure T:

26 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann26 GEADGEAD Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D Q1 Reported Intersections 1. Q1 (E--A) Status-structure T:

27 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann27 GAEDGAED Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Q2 Q3 Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) Q3 Status-structure T:

28 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann28 GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) Q3 GAEDGAED Status-structure T:

29 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann29 GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) Q3 GAEDGAED (E = F) Status-structure T:

30 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann30 G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) Q3 GAEDGAED Status-structure T:

31 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann31 G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) 4. Q4 (G--B) Q3 GAEDGAED Status-structure T:AGBCDFAGBCDF Q4

32 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann32 ABGCDFABGCDF AGBCDFAGBCDF G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q Sweep direction A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) 4. Q4 (G--B) 5. Q5 (G--C) Q3 GAEDGAED Status-structure T: Q5 Q4 Q5

33 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann33 ABGCDFABGCDF AGBCDFAGBCDF G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) 4. Q4 (G--B) 5. Q5 (G--C) Q3 GAEDGAED Status-structure T: Q4 Q5 ABGCDFABGCDF

34 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann34 ABGCDFABGCDF AGBCDFAGBCDF G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) 4. Q4 (G--B) 5. Q5 (G--C) 6. Q6 (G--D) Q3 GAEDGAED Status-structure T: Q4 Q5 ABGCDFABGCDF CGDFCGDF Q6

35 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann35 CDGFCDGF CGDFCGDF ABGCDFABGCDF AGBCDFAGBCDF G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) 4. Q4 (G--B) 5. Q5 (G--C) 6. Q6 (G--D) Q3 GAEDGAED Status-structure T: Q4 Q5 ABGCDFABGCDF Q6

36 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann36 CDGFCDGF CGDFCGDF ABGCDFABGCDF AGBCDFAGBCDF G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) 4. Q4 (G--B) 5. Q5 (G--C) 6. Q6 (G--D) Q3 GAEDGAED Status-structure T: Q4 Q5 ABGCDFABGCDF Q6 C D G F

37 Computational Geometry, WS 2007/08 Prof. Dr. Thomas Ottmann37 CDGFCDGF CGDFCGDF ABGCDFABGCDF AGBCDFAGBCDF G A B C D F GADFGADF GADEGADE Q2 Q1 Polygon Intersection by Line Sweep A B C D E F G Event-queue Q A D GEADGEAD Reported Intersections 1. Q1 (E--A) 2. Q2 (G--A) 3. Q3 (E--D) 4. Q4 (G--B) 5. Q5 (G--C) 6. Q6 (G--D) Q3 GAEDGAED Status-structure T: Q4 Q5 ABGCDFABGCDF Q6 C D G F CDCD


Download ppt "Line Segment Intersection Computational Geometry, WS 2007/08 Lecture 3 – Supplementary Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut."

Similar presentations


Ads by Google