computational geometry: intersection search joseph s. b. mitchell stony brook university
TRANSCRIPT
Computational Geometry:Computational Geometry:Intersection SearchIntersection Search
Joseph S. B. MitchellStony Brook University
Intersection SearchIntersection Search
InputInput: A set : A set SS of geometric objects of geometric objects (segments, polygons, disks, solid models, (segments, polygons, disks, solid models, etc)etc)
22
Intersection SearchIntersection Search
Versions of the problem:Versions of the problem:• DETECTDETECT: Answer yes/no: Are there any : Answer yes/no: Are there any
intersections among the objects intersections among the objects SS??
(if “yes”, then we may insist on returning a (if “yes”, then we may insist on returning a witness)witness)
• REPORTREPORT: Output all pairs of objects that intersect: Output all pairs of objects that intersect• COMPUTECOMPUTE: Compute the common intersection of all : Compute the common intersection of all
objectsobjects• COUNTCOUNT: How many pairs intersect?: How many pairs intersect?• QUERYQUERY: Preprocess : Preprocess SS to support fast queries of the to support fast queries of the
form “Does object form “Does object QQ intersect any member of intersect any member of SS?” ?” (or “Report all intersections with (or “Report all intersections with QQ”)”)
33May also want to insert/delete in S, or allow objects of S to move.
Warm Up: 1D ProblemWarm Up: 1D Problem
Given n segments (intervals) on a Given n segments (intervals) on a lineline
DETECT: O(n log n), based on sortingDETECT: O(n log n), based on sorting REPORT: O(k+n log n), based on REPORT: O(k+n log n), based on
sorting, then marching through, left sorting, then marching through, left to rightto right
Lower bound to DETECT: Lower bound to DETECT: : : (n log n) (n log n) , from ELEMENT UNIQUENESS, from ELEMENT UNIQUENESS
44
Element UniquenessInput: {x1, x2, …,xn }Are they distinct? (yes/no)(n log n)
Intersection Search: SegmentsIntersection Search: Segments Segment intersection: Given a set Segment intersection: Given a set SS
of of nn line segments in the plane, line segments in the plane, determine:determine:• Does some pair intersect? (Does some pair intersect? (DETECTDETECT))• Compute all points of intersection Compute all points of intersection
((REPORTREPORT))
Naïve: O(n2)CG: O(n log n) DETECT, O(k+n log n) REPORT
Lower Bound to DETECT: (n log n) , from ELEMENT UNIQUENESS
Element UniquenessInput: {x1, x2, …,xn }Are they distinct? (yes/no)(n log n)
Primitive ComputationPrimitive Computation
Does segment Does segment abab intersect segment intersect segment cdcd ? ?• Types of “intersect”Types of “intersect”
• Test using “Left” tests (sign of a cross Test using “Left” tests (sign of a cross product (determinant), which product (determinant), which determines the orientation of 3 points) determines the orientation of 3 points)
• Time O(1) (“constant”)Time O(1) (“constant”)66
a
bc
Left( a, b, c ) = TRUE ab ac > 0c is left of ab
Bentley-Ottmann SweepBentley-Ottmann Sweep
Main ideaMain idea: Process : Process eventsevents in order of in order of discovery as a horizontal line, discovery as a horizontal line, LL, , “sweeps” over the scene, from top to “sweeps” over the scene, from top to bottombottom
Two data structuresTwo data structures::• SLS: Sweep Line Status: left-to-right SLS: Sweep Line Status: left-to-right
ordering of the segments intersecting ordering of the segments intersecting LL• EQ: Event QueueEQ: Event Queue
77
L
Two data structures:Two data structures:• SLSSLS: Sweep Line Status: left-to-right ordering of : Sweep Line Status: left-to-right ordering of
the segments intersecting the segments intersecting LL• EQEQ: Event Queue: 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 (dictionary, support O(log n) O(log n) insert, delete, search)insert, delete, search)
• EQ: priority queue (e.g., heap)EQ: priority queue (e.g., heap)
88
O(n log n)
L
Hit top endpt of Hit top endpt of ee
Hit bottom endpt of Hit bottom endpt of ee
Hit crossing point Hit crossing point e e f f (only needed in REPORT) (only needed in REPORT)
Event HandlingEvent Handling
99
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
ef
O(log n)
O(log n)
Exchange e, f in SLS. Test(a,f), Test(b,e) and insert crossings (if any) in EQ
Algorithm AnalysisAlgorithm Analysis InvariantsInvariants of algorithm: of algorithm:
• SLS is correctly ordered. SLS is correctly ordered. • Test(Test(a,ba,b) for intersection is done whenever segments ) for intersection is done whenever segments a a and and
b b become adjacent in the SLS orderbecome 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)(for REPORT; for DETECT, stop at first detected crossing) Claim:Claim: All crossings are discovered All crossings are discovered Time: Time: O(O(n log nn log n) to DETECT ) to DETECT (O((O(nn) events @ O() events @ O(log nlog n) )) ) Time: Time: O((O((n+kn+k)) log n log n) to REPORT ) to REPORT (O((O(n+kn+k) events @ ) events @
O(O(log nlog n) )) ) Example AppletExample Applet
1010
k = # crossings = output size
Space: Working MemorySpace: Working Memory
Basic (original) version of B-O sweep: Basic (original) version of B-O sweep: Naively, the EQ has size at most Naively, the EQ has size at most O(n+k), since we store the SLS (O(n)) O(n+k), since we store the SLS (O(n)) and the EQ (size 2n+k )and the EQ (size 2n+k )
1111
Better bounds on size of EQ: O(n log2 n) [Pach and Sharir]
Space: Working MemorySpace: Working Memory
Modified B-O Sweep: Modified B-O Sweep: • Any time 2 segs STOP being adjacent in Any time 2 segs STOP being adjacent in
SLS, remove from EQ the corresponding SLS, remove from EQ the corresponding crossing point (if any); we will re-insert crossing point (if any); we will re-insert the crossing point again (at least once) the crossing point again (at least once) before the actual crossing event.before the actual crossing event.
• Note: Now the EQ has at most n-1 Note: Now the EQ has at most n-1 crossing events (and at most 2n crossing events (and at most 2n endpoint events)endpoint events)
1212
1313
1414
Optimal REPORT algorithms exist:Optimal REPORT algorithms exist:• O(O(k + n log nk + n log n), O(), O(k+nk+n) space (working memory)) space (working memory)
[Chazelle-Edelsbrunner][Chazelle-Edelsbrunner]
• O(O(k + n log nk + n log n), O(), O(nn) space ) space [Balaban][Balaban]
Special Case: REPORT for horiz/vert segsSpecial Case: REPORT for horiz/vert segs• Bentley-Ottmann sweep: O(Bentley-Ottmann sweep: O(k + n log nk + n log n) (optimal!)) (optimal!)
Special case: Simplicity testingSpecial case: Simplicity testing• O(O(nn), from Chazelle triangulation), from Chazelle triangulation
1515
(Complex)
L
All crossings happen when L hits a horizontal segment, si ; just locate (O( log n)) the endpoint and walk along horizontal segment in SLS to report all ki vertical segments crossed along si
Sweeping applies also toSweeping applies also to• UnionsUnions• IntersectionsIntersections• ArrangementsArrangements
1616
Practical Methods, 3DPractical Methods, 3D
Uniform gridUniform grid
QuadtreesQuadtrees
Bounding volume hierarchiesBounding volume hierarchies1919
With each pixel, store a list of objects intersecting it.Do brute force on pixel-by-pixel basis.
See Samet books, SAND website
Bounding Volume Bounding Volume HierarchiesHierarchies
2020
S
Bounding volume
Input: Set S of objects.
QuickCD: Collision DetectionQuickCD: Collision Detection
The 2-Box Cover ProblemThe 2-Box Cover Problem
•Find “smallest” (tightest fitting) pair of bounding boxes
•Motivation:Motivation: Best outer approximationBest outer approximation Bounding volume hierarchiesBounding volume hierarchies
Bounding Volume HierarchyBounding Volume Hierarchy
BV-tree: BV-tree: Level 0Level 0 k-dopsk-dops
BV-tree: Level 1BV-tree: Level 1
26-dops26-dops
14-dops14-dops6-dops6-dops
18-dops18-dops
BV-tree: Level 2BV-tree: Level 2
BV-tree: Level 5BV-tree: Level 5
BV-tree: Level 8BV-tree: Level 8