Collision Detection
description
Transcript of Collision Detection
![Page 1: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/1.jpg)
Collision Detection
CSCE 441
![Page 2: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/2.jpg)
2/60
What is Collision Detection?
Given two geometric objects, determine if they overlap.
Typically, at least one of the objects is a set of triangles. Rays/lines Planes Polygons Frustums Spheres Curved surfaces
![Page 3: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/3.jpg)
3/60
When Used
Often in simulations Objects move – find when they hit something else
Other examples Ray tracing speedup Culling objects/classifying objects in regions
Usually, needs to be fast Applied to lots of objects, often in real-time
applications
![Page 4: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/4.jpg)
4/60
Bounding Volumes
Key idea:Surround the object with a (simpler) bounding
object (the bounding volume).If something does not collide with the bounding
volume, it does not collide with the object inside.
Often, to intersect two
objects, first intersect their
bounding volumes
![Page 5: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/5.jpg)
5/60
Choosing a Bounding Volume
Lots of choices, each with tradeoffs
![Page 6: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/6.jpg)
6/60
Choosing a Bounding Volume
Lots of choices, each with tradeoffs Tighter fitting is better
More likely to eliminate “false” intersections
![Page 7: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/7.jpg)
7/60
Choosing a Bounding Volume
Lots of choices, each with tradeoffs Tighter fitting is better Simpler shape is better
Makes it faster to compute with
![Page 8: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/8.jpg)
8/60
Choosing a Bounding Volume
Lots of choices, each with tradeoffs Tighter fitting is better Simpler shape is better Rotation Invariant is better
Easier to update as object moves
![Page 9: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/9.jpg)
9/60
Choosing a Bounding Volume
Lots of choices, each with tradeoffs Tighter fitting is better Simpler shape is better Rotation Invariant is better Convex is usually better
Gives simpler shape, easier computation
![Page 10: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/10.jpg)
10/60
Common Bounding Volumes: Sphere
Rotationally invariant Usually
Usually fast to compute with Store: center point and radius
Center point: object’s center of mass
Radius: distance of farthest point on object from center of mass.
Often not very tight fit
![Page 11: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/11.jpg)
11/60
Common Bounding Volumes:Axis Aligned Bounding Box (AABB)
Very fast to compute with Store: max and min along x,y,z
axes. Look at all points and record
max, min Moderately tight fit Must update after rotation, unless
a loose box that encompasses the bounding sphere
![Page 12: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/12.jpg)
12/60
Common Bounding Volumes: k-dops
k-discrete oriented polytopes Same idea as AABBs, but
use more axes. Store: max and min along
fixed set of axes.Need to project points
onto other axes. Tighter fit than AABB, but
also a bit more work.
![Page 13: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/13.jpg)
13/60
Choosing axes for k-dops
Common axes: consider axes coming out from center of a cube:
Through faces: 6-dop same as AABB
Faces and vertices: 14-dop Faces and edge centers: 18-dop Faces, vertices, and edge centers; 26-
dop More than that not really helpful Empirical results show 14 or 18-dop
performs best.
![Page 14: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/14.jpg)
14/60
Common Bounding Volumes:Oriented Bounding Box (OBB) Store rectangular parallelepiped oriented
to best fit the object Store:
Center Orthonormal set of axes Extent along each axis
Tight fit, but takes work to get good initial fit
OBB rotates with object, therefore only rotation of axes is needed for update
Computation is slower than for AABBs, but not as bad as it might seem
![Page 15: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/15.jpg)
15/60
Common Bounding Volumes:Convex Hull
Very tight fit (tightest convex bounding volume)
Slow to compute with Store: set of polygons
forming convex hull Can rotate CH along with
object. Can be efficient for some
applications
![Page 16: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/16.jpg)
16/60
Testing for Collision
Will depend on type of objects and bounding volumes.
Specialized algorithms for each:Sphere/sphereAABB/AABBOBB/OBBRay/sphereTriangle/Triangle
![Page 17: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/17.jpg)
17/60
Collision Test ExampleSphere-Sphere
Find distance between centers of spheres Compare to sum of sphere radii
If distance is less, they collide For efficiency, check squared distance vs.
square of sum of radii
dr2
r1
![Page 18: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/18.jpg)
18/60
Collision Test ExampleAABB vs. AABB
Project AABBs onto axes i.e. look at extents
If overlapping on all axes, the boxes overlap. Same idea
for k-dops.
![Page 19: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/19.jpg)
19/60
Collision Test ExampleOBB vs. OBB
How do we determine if two oriented bounding boxes overlap?
![Page 20: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/20.jpg)
20/60
Separating Axis Theorem
Two convex shapes do not overlap if and only if there exists an axis such that the projections of the two shapes do not overlap
![Page 21: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/21.jpg)
21/60
Enumerating Separating Axes
2D: check axis aligned with normal of each face
3D: check axis aligned with normals of each face and cross product of each pair of edges
![Page 22: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/22.jpg)
22/60
Enumerating Separating Axes
2D: check axis aligned with normal of each face
3D: check axis aligned with normals of each face and cross product of each pair of edges
![Page 23: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/23.jpg)
23/60
Enumerating Separating Axes
2D: check axis aligned with normal of each face
3D: check axis aligned with normals of each face and cross product of each pair of edges
![Page 24: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/24.jpg)
24/60
Enumerating Separating Axes
2D: check axis aligned with normal of each face
3D: check axis aligned with normals of each face and cross product of each pair of edges
![Page 25: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/25.jpg)
25/60
Enumerating Separating Axes
2D: check axis aligned with normal of each face
3D: check axis aligned with normals of each face and cross product of each pair of edges
![Page 26: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/26.jpg)
26/60
Collision Test ExampleTriangle-Triangle
Many collision detection tests eventually reduce to this.
Two common approaches. Both involve finding the plane a triangle lies in.Cross product of edges to get triangle normal.This is the plane normal [A B C] where plane
is Ax+By+Cz+D=0Solve for D by plugging in a triangle vertex
![Page 27: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/27.jpg)
27/60
Triangle-Triangle Collision 1
Find line of intersection between triangle planes.
Find extents of triangles along this line If extents overlap, triangles intersect.
![Page 28: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/28.jpg)
28/60
Triangle-Triangle Collision 2
Intersect edges of one triangle with plane of the other triangle.
2 edges will intersect – form line segment in plane.
Test that 2D line segment against triangle.
![Page 29: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/29.jpg)
29/60
Bounding Volume Hierarchies
What happens when the bounding volumes do intersect?We must test whether the actual objects
underneath intersect.For an object made from lots of polygons,
this is complicated.So, we will use a bounding volume
hierarchy
![Page 30: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/30.jpg)
30/60
Bounding Volume Hierarchies
Highest level of hierarchy – single BV around whole object
Next level – subdivide the object into two (or maybe more) parts.Each part gets its own BV
Continue recursively until only one triangle remains
![Page 31: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/31.jpg)
31/60
Bounding Volume Hierarchy Example
![Page 32: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/32.jpg)
32/60
Bounding Volume Hierarchy Example
![Page 33: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/33.jpg)
33/60
Bounding Volume Hierarchy Example
![Page 34: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/34.jpg)
34/60
Bounding Volume Hierarchy Example
![Page 35: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/35.jpg)
35/60
Bounding Volume Hierarchy Example
![Page 36: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/36.jpg)
36/60
Bounding Volume Hierarchy Example
![Page 37: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/37.jpg)
37/60
Bounding Volume Hierarchy Example
![Page 38: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/38.jpg)
38/60
Bounding Volume Hierarchy Example
![Page 39: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/39.jpg)
39/60
Bounding Volume Hierarchy Example
![Page 40: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/40.jpg)
40/60
Bounding Volume Hierarchy Example
![Page 41: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/41.jpg)
41/60
Bounding Volume Hierarchy Example
![Page 42: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/42.jpg)
42/60
Bounding Volume Hierarchy Example
![Page 43: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/43.jpg)
43/60
Intersecting Bounding Volume Hierarcies For object-object collision detection Keep a queue of potentially intersecting BVs
Initialize with main BV for each object Repeatedly pull next potential pair off queue and test
for intersection. If that pair intersects, put pairs of children into
queue. If no child for both BVs, test triangles inside
Stop when we either run out of pairs (thus no intersection) or we find an intersecting pair of triangles
![Page 44: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/44.jpg)
44/60
BVH Collision Test example
![Page 45: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/45.jpg)
45/60
BVH Collision Test example
![Page 46: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/46.jpg)
46/60
BVH Collision Test example
![Page 47: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/47.jpg)
47/60
BVH Collision Test example
![Page 48: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/48.jpg)
48/60
BVH Collision Test example
![Page 49: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/49.jpg)
49/60
BVH Collision Test example
![Page 50: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/50.jpg)
50/60
BVH Collision Test example
![Page 51: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/51.jpg)
51/60
BVH Collision Test example
![Page 52: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/52.jpg)
52/60
BVH Collision Test example
![Page 53: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/53.jpg)
53/60
BVH Collision Test example
![Page 54: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/54.jpg)
54/60
BVH Collision Test example
![Page 55: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/55.jpg)
55/60
BVH Collision Test example
![Page 56: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/56.jpg)
56/60
Broad Phase vs. Narrow Phase
What we have talked about so far is the “narrow phase” of collision detection.Testing whether two particular objects
collide The “broad phase” assumes we have a number
of objects, and we want to find out all pairs that collide.
Testing every pair is inefficient
![Page 57: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/57.jpg)
57/60
Broad Phase Collision Detection
Form an AABB for each object Pick an axis
Sort objects along that axisFind overlapping pairs along that axisFor overlapping pairs, check along other
axes. Limits the number of object/object tests Overlapping pairs then sent to narrow phase
![Page 58: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/58.jpg)
Broad Phase Collision Detection
58/60
![Page 59: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/59.jpg)
59/60
Collision Detection in a Physically-Based Simulation
Must account for object motion Obeys basic physical laws – integration of
differential equations Collision detection: yes/no
Collision determination: where do they intersect Collision response: how do we adjust the motion
of objects in response to collision Collision determination/response are more difficult,
but are key for physically based simulation.
![Page 60: Collision Detection](https://reader035.fdocuments.in/reader035/viewer/2022062217/5681459f550346895db293ae/html5/thumbnails/60.jpg)
60/60
Some Other Issues
Constructing an optimal BVH Convergence of BVH (i.e. how fast do the
BVs approach the actual object).OBBs asymptotically better, here
Optimizing individual tests Handling stacking and rest contacts