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

Slides:



Advertisements
Similar presentations
Order-k Voronoi Diagram in the Plane
Advertisements

Linear Programming Computational Geometry, WS 2006/07 Lecture 5, Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Two Segments Intersect?
Interval Heaps Complete binary tree. Each node (except possibly last one) has 2 elements. Last node has 1 or 2 elements. Let a and b be the elements in.
Computational Geometry
Introduction to Computational Geometry Computational Geometry, WS 2007/08 Lecture 1 – Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut.
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Lecture 3: Parallel Algorithm Design
Brute-Force Triangulation
Computational Geometry, WS 2007/08 Lecture 17 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für Angewandte Wissenschaften.
Convex Hulls Computational Geometry, WS 2007/08 Lecture 2 – Supplementary Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,
Lecture 3 Lower envelopes Computational Geometry, 2005/06 Prof.Dr.Th.Ottmann 1 The Lower Envelope The Pointwise Minimum of a Set of Functions.
Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.
Robert Pless, CS 546: Computational Geometry Lecture #3 Last Time: Convex Hulls Today: Plane Sweep Algorithms, Segment Intersection, + (Element Uniqueness,
Convex Hulls Computational Geometry, WS 2006/07 Lecture 2 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
Klee’s Measure Problem Computational Geometry, WS 2007/08 Group Work Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.
The Half-Edge Data Structure Computational Geometry, WS 2007/08 Lecture 3, Part III Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen,
Linear Programming Computational Geometry, WS 2006/07 Lecture 5, Part IV Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 – Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
The Half-Edge Data Structure
Delaunay Triangulation Computational Geometry, WS 2006/07 Lecture 11 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Line Segment Intersection Computational Geometry, WS 2007/08 Lecture 3 – Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
The Lower Envelope: The Pointwise Minimum of a Set of Functions Computational Geometry, WS 2006/07 Lecture 4 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen,
Lecture 12 : Special Case of Hidden-Line-Elimination Computational Geometry Prof. Dr. Th. Ottmann 1 Special Cases of the Hidden Line Elimination Problem.
Special Cases of the Hidden Line Elimination Problem Computational Geometry, WS 2007/08 Lecture 16 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen,
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Voronoi Diagrams Computational Geometry, WS 2006/07 Lecture 10 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Duality and Arrangements Computational Geometry, WS 2007/08 Lecture 6 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Introduction to Computational Geometry Computational Geometry, WS 2007/08 Lecture 1 – Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut.
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 – Part III Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
Persistent Data Structures Computational Geometry, WS 2007/08 Lecture 12 Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen, Institut.
2 -1 Analysis of algorithms Best case: easiest Worst case Average case: hardest.
Linear Programming Computational Geometry, WS 2007/08 Lecture 7 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Parallel Merging Advanced Algorithms & Data Structures Lecture Theme 15 Prof. Dr. Th. Ottmann Summer Semester 2006.
Geometric Data Structures Computational Geometry, WS 2007/08 Lecture 13 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Hidden-Line Elimination Computational Geometry, WS 2006/07 Lecture 14 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Linear Programming Computational Geometry, WS 2007/08 Lecture 7, Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Point Location Computational Geometry, WS 2007/08 Lecture 5 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät für.
Closest Pair of Points Computational Geometry, WS 2006/07 Lecture 9, Part II Prof. Dr. Thomas Ottmann Khaireel A. Mohamed Algorithmen & Datenstrukturen,
Polygon Triangulation Computational Geometry, WS 2007/08 Lecture 9 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Linear Programming Computational Geometry, WS 2006/07 Lecture 5, Part III Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Orthogonal Range Searching Computational Geometry, WS 2006/07 Lecture 13 - Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
Lecture 6: Point Location Computational Geometry Prof. Dr. Th. Ottmann 1 Point Location 1.Trapezoidal decomposition. 2.A search structure. 3.Randomized,
Lecture 11 : More Geometric Data Structures Computational Geometry Prof. Dr. Th. Ottmann 1 Geometric Data Structures 1.Rectangle Intersection 2.Segment.
Polygon Triangulation Computational Geometry, WS 2006/07 Lecture 8, Part 2 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Linear Programming Computational Geometry, WS 2006/07 Lecture 5, Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Line Segment Intersection Computational Geometry, WS 2006/07 Lecture 3 – Part II Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Lecture 2 Line Segment Intersection Computational Geometry Prof.Dr.Th.Ottmann 1 Line Segment Intersection Motivation: Computing the overlay of several.
Art Gallery Theorem Computational Geometry, WS 2006/07 Lecture 8, Part 1 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
Duality and Arrangements Computational Geometry, WS 2006/07 Lecture 7 Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik Fakultät.
Line Segment Intersection Computational Geometry, WS 2006/07 Lecture 3 – Part I Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für Informatik.
MergeSort Source: Gibbs & Tamassia. 2 MergeSort MergeSort is a divide and conquer method of sorting.
Lection 1: Introduction Computational Geometry Prof.Dr.Th.Ottmann 1 History: Proof-based, algorithmic, axiomatic geometry, computational geometry today.
Brute-Force Triangulation
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
1 Geometric Intersection Determining if there are intersections between graphical objects Finding all intersecting pairs Brute Force Algorithm Plane Sweep.
UNC Chapel Hill M. C. Lin Line Segment Intersection Chapter 2 of the Textbook Driving Applications –Map overlap problems –3D Polyhedral Morphing.
Line Segment Intersection Computational Geometry, WS 2006/07 Lecture 3 – Part III Prof. Dr. Thomas Ottmann Algorithmen & Datenstrukturen, Institut für.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
CMPS 3130/6130 Computational Geometry Spring 2015
8 January Heap Sort CSE 2011 Winter Heap Sort Consider a priority queue with n items implemented by means of a heap  the space used is.
Quick sort, lower bound on sorting, bucket sort, radix sort, comparison of algorithms, code, … Sorting: part 2.
CS6045: Advanced Algorithms Sorting Algorithms. Heap Data Structure A heap (nearly complete binary tree) can be stored as an array A –Root of tree is.
CMPS 3130/6130 Computational Geometry Spring 2017
Algorithm design techniques Dr. M. Gavrilova
Objectives Introduce different known sorting algorithms
(2,4) Trees 11/15/2018 9:25 AM Sorting Lower Bound Sorting Lower Bound.
Computational Geometry Capter:1-2.1
(2,4) Trees 2/28/2019 3:21 AM Sorting Lower Bound Sorting Lower Bound.
Presentation transcript:

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

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

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)

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

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:.

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)

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

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!

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)!

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

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

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

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 )

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

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

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

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

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

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 ]}

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

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

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

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

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

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:

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:

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:

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:

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:

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:

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

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

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

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

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

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

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