200 likes | 350 Views
Basic 3D collision detection. We want to know if objects have touched Objects are considered to be in continuous motion (vertices are changing) We want to do this stuff FAST!!!. We’ll only do…. Convex polyhedra Objects will be broken into convex polyhedra or we’ll use an enclosing polyhedron
E N D
Basic 3D collision detection • We want to know if objects have touched • Objects are considered to be in continuous motion (vertices are changing) • We want to do this stuff FAST!!!
We’ll only do… • Convex polyhedra • Objects will be broken into convex polyhedra or we’ll use an enclosing polyhedron • Definition • A line segment joining any two points in the polyhedron is contained in the polyhedron
Two stage process • Bounding boxes • Only test if bounding boxes intersect • Witness test • See if we can stick a plane between them
Bounding box tests • We will not even consider O(N2). • Even for something as easy as bounding boxes
Suppose… • You have a set of line segments • [bi,ei] beginning to end • Bounding boxes in 1D • How could we determine if any overlap? • How fast could I do it?
Overlap test b1 b5 e1 e5 b4 b2 e2 e4 b3 e3 b6 e6 Any ideas now?
Overlap test (1D) O(nlogn + k) algorithm Sort and sweep b1 b5 e1 e5 b4 b2 e2 e4 b3 e3 b6 e6 E sort(endpoints) O(nlogn) c 0 for each endpoint eE do O(n) if e is a begin endpoint c c + 1 else c c - 1 if c > 1 then output overlapping segments O(k)
Overlap test (3D) • We have begin/end combinations for each of 3 dimensions • We build three sorted lists • Each dimension • Sweep 1 dimension • Sweep 2nd dimension only for overlaps • Sweep 3rd dimension only for overlaps • Algorithm remains O(nlogn + k) • Lots of careful “bookkeeping” required. • Sometimes called sweep and prune
Can we do better than O(nlogn)? • Algorithmically we can’t • Lower bound • But…
Coherence • What will make this work is that things do move very far from frame to frame • Coherence • When we update a bounding box, we change the ends • But, usually not be much • Just move it in the list • Expected time: O(n) bingo!!
So, we have two intersecting bounding boxes, what now? • We compare the enclosed polyhedra • What defines intersecting polyhedra?
Intersection definition • Two polyhedra A and B do NOT intersect if there exists a plane P such that A and B are on different sides of P • We call this plane a separating plane • It indicates there’s no intersection • Only works for convex polyhedra
Separating planes • Separating planes will either • Contain a face of one of the polyhedra • - or - • Contain the edge of one polyhedra and are parallel to an edge in the other polyhedra
Determining intersection • For every face and every pair of edges • Is this is a separating plane? • How do we test for space partitioning?
Test • Let p be any point on P and N be normal to P • Dot product of v-p and N will be: • >= 0 for someone on one side • <= 0 for someone on the other side
Contact determination • Can be vertex to plane or edge to edge. We have to again test all pairs
Fast enough to be any use? • Lots of all pairs stuff here. • Can this be fast enough to be any use at all? • How often do we call collision detection?
Witness • A witness is some cached value from a previous computation that we can reuse • Keep track of – • Previous separating plane • Previous collision pair • Why does this make this so fast we’re really impressed?
Use of witnesses • Change from one call to another is very tiny • Separating plane usually does not change • Can it? • We are often searching for the collision time • Colliding edges or face/vertex usually do not change • Can they?