Download presentation
Presentation is loading. Please wait.
Published byArron Stokes Modified over 9 years ago
1
Computational Geometry: Intersection Search Joseph S. B. Mitchell Stony Brook University
2
Intersection Search Input: A set S of geometric objects (segments, polygons, disks, solid models, etc) Input: A set S of geometric objects (segments, polygons, disks, solid models, etc) 2
3
Intersection Search Versions of the problem: Versions of the problem: DETECT: Answer yes/no: Are there any intersections among the objects S?DETECT: Answer yes/no: Are there any intersections among the objects S? (if “yes”, then we may insist on returning a witness) REPORT: Output all pairs of objects that intersectREPORT: Output all pairs of objects that intersect COMPUTE: Compute the common intersection of all objectsCOMPUTE: Compute the common intersection of all objects COUNT: How many pairs intersect?COUNT: How many pairs intersect? QUERY: Preprocess S to support fast queries of the form “Does object Q intersect any member of S?” (or “Report all intersections with Q”)QUERY: Preprocess S to support fast queries of the form “Does object Q intersect any member of S?” (or “Report all intersections with Q”) 3 May also want to insert/delete in S, or allow objects of S to move.
4
Warm Up: 1D Problem Given n segments (intervals) on a line Given n segments (intervals) on a line DETECT: O(n log n), based on sorting DETECT: O(n log n), based on sorting REPORT: O(k+n log n), based on sorting, then marching through, left to right REPORT: O(k+n log n), based on sorting, then marching through, left to right Lower bound to DETECT: : (n log n), from ELEMENT UNIQUENESS Lower bound to DETECT: : (n log n), from ELEMENT UNIQUENESS 4 Element Uniqueness Input: {x 1, x 2, …,x n } Are they distinct? (yes/no) (n log n)
5
Intersection Search: Segments Segment intersection: Given a set S of n line segments in the plane, determine: Segment intersection: Given a set S of n line segments in the plane, determine: Does some pair intersect? (DETECT)Does some pair intersect? (DETECT) Compute all points of intersection (REPORT)Compute all points of intersection (REPORT) Naïve: O(n 2 ) CG: O(n log n) DETECT, O(k+n log n) REPORT Lower Bound to DETECT: (n log n), from ELEMENT UNIQUENESS Element Uniqueness Input: {x 1, x 2, …,x n } Are they distinct? (yes/no) (n log n)
6
Primitive Computation Does segment ab intersect segment cd ? Does segment ab intersect segment cd ? Types of “intersect”Types of “intersect” Test using “Left” tests (sign of a cross product (determinant), which determines the orientation of 3 points)Test using “Left” tests (sign of a cross product (determinant), which determines the orientation of 3 points) Time O(1) (“constant”)Time O(1) (“constant”) 6 a b c Left( a, b, c ) = TRUE ab ac > 0 c is left of ab
7
Bentley-Ottmann Sweep Main idea: Process events in order of discovery as a horizontal line, L, “sweeps” over the scene, from top to bottom Main idea: Process events in order of discovery as a horizontal line, L, “sweeps” over the scene, from top to bottom Two data structures: Two data structures: SLS: Sweep Line Status: left-to-right ordering of the segments intersecting LSLS: Sweep Line Status: left-to-right ordering of the segments intersecting L EQ: Event QueueEQ: Event Queue 7 L
8
Two data structures: Two data structures: SLS: Sweep Line Status: left-to-right ordering of the segments intersecting LSLS: Sweep Line Status: left-to-right ordering of the segments intersecting L EQ: Event QueueEQ: Event Queue Initialize: Initialize: SLS = SLS = EQ = sorted list of segment endpointsEQ = sorted list of segment endpoints How to store: How to store: SLS: balanced binary search treeSLS: balanced binary search tree (dictionary, support O(log n) insert, delete, search) (dictionary, support O(log n) insert, delete, search) EQ: priority queue (e.g., heap)EQ: priority queue (e.g., heap) 8 O(n log n) L
9
Hit top endpt of e Hit top endpt of e Hit bottom endpt of e Hit bottom endpt of e Hit crossing point e f (only needed in REPORT) Hit crossing point e f (only needed in REPORT) Event Handling 9 O(log n) L a b e Find segs a and b left/right of e in SLS. Insert e into SLS. Test(a,e), Test(b,e) and insert crossings (if any) in EQ a b e L Find segs a and b left/right of e in SLS. Delete e from SLS. Test(a,b), and insert crossing (if any) in EQ a b L e f O(log n) Exchange e, f in SLS. Test(a,f), Test(b,e) and insert crossings (if any) in EQ
10
Algorithm Analysis Invariants of algorithm: Invariants of algorithm: SLS is correctly ordered.SLS is correctly ordered. Test(a,b) for intersection is done whenever segments a and b become adjacent in the SLS orderTest(a,b) for intersection is done whenever segments a and b become adjacent in the SLS order Discovered crossings are inserted into EQ Discovered crossings are inserted into EQ (for REPORT; for DETECT, stop at first detected crossing) Claim: All crossings are discovered Claim: All crossings are discovered Time: O(n log n) to DETECT (O(n) events @ O(log n) ) Time: O(n log n) to DETECT (O(n) events @ O(log n) ) Time: O((n+k) log n) to REPORT (O(n+k) events @ O(log n) ) Time: O((n+k) log n) to REPORT (O(n+k) events @ O(log n) ) Example Applet Example Applet Example Applet Example Applet 10 k = # crossings = output size
11
Space: Working Memory Basic (original) version of B-O sweep: Naively, the EQ has size at most O(n+k), since we store the SLS (O(n)) and the EQ (size 2n+k ) Basic (original) version of B-O sweep: Naively, the EQ has size at most O(n+k), since we store the SLS (O(n)) and the EQ (size 2n+k ) 11 Better bounds on size of EQ: O(n log 2 n) [Pach and Sharir]
12
Space: Working Memory Modified B-O Sweep: Modified B-O Sweep: Any time 2 segs STOP being adjacent in SLS, remove from EQ the corresponding crossing point (if any); we will re-insert the crossing point again (at least once) before the actual crossing event.Any time 2 segs STOP being adjacent in SLS, remove from EQ the corresponding crossing point (if any); we will re-insert the crossing point again (at least once) before the actual crossing event. Note: Now the EQ has at most n-1 crossing events (and at most 2n endpoint events)Note: Now the EQ has at most n-1 crossing events (and at most 2n endpoint events) 12
13
13
14
14
15
Optimal REPORT algorithms exist: Optimal REPORT algorithms exist: O(k + n log n), O(k+n) space (working memory)O(k + n log n), O(k+n) space (working memory) [Chazelle-Edelsbrunner] [Chazelle-Edelsbrunner] O(k + n log n), O(n) space [Balaban]O(k + n log n), O(n) space [Balaban] Special Case: REPORT for horiz/vert segs Special Case: REPORT for horiz/vert segs Bentley-Ottmann sweep: O(k + n log n) (optimal!)Bentley-Ottmann sweep: O(k + n log n) (optimal!) Special case: Simplicity testing Special case: Simplicity testing O(n), from Chazelle triangulationO(n), from Chazelle triangulation 15 (Complex) L All crossings happen when L hits a horizontal segment, s i ; just locate (O( log n)) the endpoint and walk along horizontal segment in SLS to report all k i vertical segments crossed along s i
16
Sweeping applies also to Sweeping applies also to UnionsUnions IntersectionsIntersections ArrangementsArrangements 16
17
Data Structures for Planar Subdivisions Winged Edge Data Structure. Winged Edge Data Structure. Quad Edge Data Structure. Quad Edge Data Structure. Our focus on “Doubly Connected Edge List”. Our focus on “Doubly Connected Edge List”. [ DCEL: doubly connected edge list ] f0f0f0f0 f1f1f1f1 e e 4,0 v1v1v1v1 v0v0v0v0 - represent edge as 2 halves - lists: vertex, face, edge/twin -facilitates face traversal e’s twin v2v2v2v2 v7v7v7v7 v6v6v6v6 v5v5v5v5 v3v3v3v3 v4v4v4v4 e 0,1 Every edge e is struct: –e.org, e.dest: pointer to origin and dest vertices. –e.face is face on left of edge –e.twin is the same edge, oriented the other direction. –e.next is next edge along the face Ack: R. Pless
18
DCEL f0f0 f1f1 e e 4,0 v1v1 v0v0 Pop quiz. -How to enumerate all edges of a face? -How to enumerate all edges incident on a node? e’s twin v2v2 v7v7 v6v6 v5v5 v3v3 v4v4 e 0,1 Every edge e is struct: –e.org, e.dest: pointer to origin and dest vertices. –e.face is face on left of edge –e.twin is the same edge, oriented the other direction. Each Face has a pointer to one edge of that face. Each vertex has pointer to one edge away from that vertex. Ack: R. Pless
19
Practical Methods, 3D Uniform grid Uniform grid Quadtrees Quadtrees Bounding volume hierarchies Bounding volume hierarchies 19 With each pixel, store a list of objects intersecting it. Do brute force on pixel-by-pixel basis. See Samet books, SAND websiteSAND
20
Bounding Volume Hierarchies 20 S Bounding volume Input: Set S of objects.
21
QuickCD: Collision Detection
22
The 2-Box Cover Problem Find “smallest” (tightest fitting) pair of bounding boxes Motivation:Motivation: Best outer approximation Best outer approximation Bounding volume hierarchies Bounding volume hierarchies
23
Bounding Volume Hierarchy BV-tree: Level 0 k-dops
24
BV-tree: Level 1 26-dops 14-dops 6-dops 18-dops
25
BV-tree: Level 2
26
BV-tree: Level 5
27
BV-tree: Level 8
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.