collisions using separating-axis tests christer ericson sony computer entertainment slides @
TRANSCRIPT
![Page 1: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/1.jpg)
Collisions using Collisions using separating-axis testsseparating-axis tests
Christer EricsonSony Computer Entertainment
Slides @ http://realtimecollisiondetection.net/pubs/
![Page 2: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/2.jpg)
Problem statement
Determine if two (convex) objects are intersecting.
Possibly also obtain contact information.
?A B
!A B
![Page 3: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/3.jpg)
Underlying theory
Set C is convex if and only if the line segment between any two points in C lies in C.
![Page 4: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/4.jpg)
Underlying theory
Separating Hyperplane Theorem States: two disjoint convex sets are
separable by a hyperplane.
![Page 5: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/5.jpg)
Underlying theory
Nonintersecting concave sets not generally separable by hyperplane (only by hypersurfaces).
Concave objects not covered here.
![Page 6: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/6.jpg)
Underlying theory
Separation w.r.t a plane P separation of the orthogonal projections onto any line L parallel to plane normal.
A B
L
P
![Page 7: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/7.jpg)
Underlying theory
A line for which the projection intervals do not overlap we call a separating axis.
A B
L
P
![Page 8: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/8.jpg)
Separated if
or
Testing separation
Compare absolute intervals
minA
a
maxA minB maxB
A
B
max minA B
max minB A
![Page 9: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/9.jpg)
Testing separation
For centrally symmetric objects: compare using projected radii
A
B
BrAr
t
aˆt a
Separated ifˆ
A Br r t a
![Page 10: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/10.jpg)
Code fragment
void GetInterval(Object o, Vector axis,
float &min, float &max) {
min = max = Dot(axis, o.getVertex(0));
for (int i = 1, n = o.NumVertices(); i < n; i++) {
float value = Dot(axis, o.getVertex(i));
min = Min(min, value);
max = Max(max, value);
}
}
![Page 11: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/11.jpg)
Axes to test
But which axes to test? Potentially infinitely many!
Simplification: Deal only with polytopes
Convex hulls of finite point sets Planar faces
![Page 12: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/12.jpg)
Axes to test
Handwavingly: Look at the ways features of A and B
can come into contact. Features are vertices, edges, faces. In 3D, reduces to vertex-face and edge-edge
contacts. Vertex-face:
a face normal from either polytope will serve as a separating axis.
Edge-edge: the cross product of an edge from each will
suffice.
![Page 13: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/13.jpg)
Axes to test
Theoretically: Consider the Minkowski difference C of
A and B. When A and B disjoint, origin outside C,
specifically outside some face F. Faces of C come from A, from B, or
from sweeping the faces of either along the edges of the other.
Therefore the face normal of F is either from A, from B, or the cross product of an edge from either.
![Page 14: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/14.jpg)
Axes to test
Four axes for two 2D OBBs:
![Page 15: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/15.jpg)
3D ObjectsFace dirs
(A)Face dirs
(B)Edge dirs
(AxB)Total
Segment–Tri 0 1 1x3 4
Segment–OBB 0 3 1x3 6
AABB–AABB 3 0(3) 0(3x0) 3
OBB–OBB 3 3 3x3 15
Tri–Tri 1 1 3x3 11
Tri–OBB 1 3 3x3 13
Axes to test
![Page 16: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/16.jpg)
Code fragmentbool TestIntersection(Object o1, Object o2) { float min1, max1, min2, max2; for (int i = 0, n = o1.NumFaceDirs(), i < n; i++) { GetInterval(o1, o1.GetFaceDir(i), min1, max1); GetInterval(o2, o1.GetFaceDir(i), min2, max2); if (max1 < min2 || max2 < min1) return false; } for (int i = 0, n = o2.NumFaceDirs(), i < n; i++) { GetInterval(o1, o2.GetFaceDir(i), min1, max1); GetInterval(o2, o2.GetFaceDir(i), min2, max2); if (max1 < min2 || max2 < min1) return false; } for (int i = 0, m = o1.NumEdgeDirs(), i < m; i++) for (int j = 0, n = o2.NumEdgeDirs(), j < n; j++) { Vector axis = Cross(o1.GetEdgeDir(i), o2.GetEdgeDir(j)); GetInterval(o1, axis, min1, max1); GetInterval(o2, axis, min2, max2); if (max1 < min2 || max2 < min1) return false; } return true;}
Note: here objects assumed to be in the same space.
![Page 17: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/17.jpg)
Moving objects
When objects move, projected intervals move:
![Page 18: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/18.jpg)
Moving objects
Objects intersect when projections overlap on all axes.
If tifirst and ti
last are time of first and last contact on axis i, then objects are in contact over the interval [maxi { ti
first}, mini { ti
last}].
No contact if maxi { tifirst} > mini { ti
last}
![Page 19: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/19.jpg)
Moving objects
Optimization 1: Consider relative movement only. Shrink interval A to point, growing
interval B by original width of A. Becomes moving point vs. stationary
interval. Optimization 2:
Exit as soon as maxi { tifirst} > mini { ti
last}
![Page 20: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/20.jpg)
Nonpolyhedral objects
What about: Spheres, capsules, cylinders, cones,
etc? Same idea:
Identify all ‘features’ Test all axes that can possibly separate
feature pairs!
![Page 21: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/21.jpg)
Nonpolyhedral objects
Sphere tests: Has single feature: its center Test axes going through center (Radius is accounted for during overlap
test on axis.)
![Page 22: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/22.jpg)
Nonpolyhedral objects
Capsule tests: Split into three features Test axes that can separate features of
capsule and features of second object.
![Page 23: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/23.jpg)
Nonpolyhedral objects
Sphere vs. OBB test: sphere center vs. box vertex
pick candidate axis parallel to line thorugh both points.
sphere center vs. box edge pick candidate axis parallel to line perpendicular
to edge and goes through sphere center sphere center vs. box face
pick candidate axis parallel to line through sphere center and perpendicular to face
Use logic to reduce tests where possible.
![Page 24: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/24.jpg)
Nonpolyhedral objects
For sphere-OBB, all tests can be subsumed by a single axis test:
Closest point on OBB to sphere center
![Page 25: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/25.jpg)
Robustness warning
Cross product of edges can result in zero-vector.
if (Dot(foo, axis) > Dot(bar, axis)) return false;
if (epsilon1 > epsilon2) return false;
Typical test:
Becomes, due to floating-point errors:
Results in: Chaos!
(Address using means discussed earlier.)
![Page 26: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/26.jpg)
Contact determination
Covered by Erin Catto (later)
![Page 27: Collisions using separating-axis tests Christer Ericson Sony Computer Entertainment Slides @](https://reader033.vdocuments.us/reader033/viewer/2022061306/55148406550346ea6e8b4b1a/html5/thumbnails/27.jpg)
References
Ericson, Christer. Real-Time Collision Detection. Morgan Kaufmann 2005. http://realtimecollisiondetection.net/
Levine, Ron. “Collisions of moving objects.” gdalgorithms-list mailing list article, November 14, 2000. http://realtimecollisiondetection.net/files/levine_swept_sat.txt
Boyd, Stephen. Lieven Vandenberghe. Convex Optimization. Cambridge University Press, 2004. http://www.stanford.edu/~boyd/cvxbook/
Rockafellar, R. Tyrrell. Convex Analysis. Princeton University Press, 1996.