collision handling: detection and response
DESCRIPTION
Collision handling: detection and response. CSE 3541 Matt Boggus. Collision handling overview. Point collision detection Line segment and ray collision detection Polyhedron-polyhedron collision detection Bounding volume test Vertex inside polyhedron test Concave case - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/1.jpg)
Collision handling:detection and response
CSE 3541Matt Boggus
![Page 2: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/2.jpg)
Collision handling overview
Point collision detectionLine segment and ray collision detectionPolyhedron-polyhedron collision detection
Bounding volume testVertex inside polyhedron test
Concave caseConvex case
Edge-face intersection test
Kinematic response
Penalty method
detection
response
![Page 3: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/3.jpg)
Geometric modeling primitives
• Point
• Line segment
• Polygon
![Page 4: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/4.jpg)
Terminology – convex and concave polygons
![Page 5: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/5.jpg)
Convex and concave – line test
![Page 6: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/6.jpg)
Convex and concave – interior angles
![Page 7: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/7.jpg)
Polygon triangulationsplit into a set of convex polygons
![Page 8: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/8.jpg)
Types of equations
• Explicit y = f(x)– Ex: y = mx + b
• Implicit f(x,y) = 0– Ex: x2 + y2 – 1 = 0– Given values for (x,y), say x = a and y = b, compute f(a,b) = c
• c > 0, then (a,b) is “outside” shape f• c = 0, then (a,b) is on the boundary/surface of shape f• c < 0, then (a,b) is “inside” shape f
• Parametric form (x,y) = (f(u),g(u))– Ex: x = f(t) = r cos (t) , y = g(t) = r sin (t)– Given any value for t parameter, compute a point (x,y)
![Page 9: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/9.jpg)
Parametric line equation• P(t) = P0 + t V– P0 is point on line– V is direction (or slope) of line– On line segment with P1, t ranges from (0,1)
• x = P0.x + t * (P1 – P0).x
• y = P0.y + t * (P1 – P0).y
![Page 10: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/10.jpg)
Point on a line segment• Given (x,y), is it on a line segment (P1 to P0)?
• x = P0.x + tx * (P1 – P0).x
• y = P0.y + ty * (P1 – P0).y
• Plug in x, y, P0, P1, solve for tx and ty
• On the segment if 0 ≤ tx = ty ≤ 1
![Page 11: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/11.jpg)
Examples
• P0 = (0,0)
• P1 = (1,1)
• P = (0.5, 0.5)• P = (-1, -1)• P = (2, 2)• P = (5, 0)
![Page 12: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/12.jpg)
Line intersection – two equations
• Pa = P0 + ta (P1 – P0)
• Pb = P2 + tb (P3 – P2)
• Set them equal, solve for ta and tb
– Note that these are vector equations, not scalars
• Line segment intersection if – 0 <= ta <= 1, and
– 0 <= tb <= 1
![Page 13: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/13.jpg)
Line intersection – visual example
![Page 14: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/14.jpg)
Point in polygon – ray test
![Page 15: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/15.jpg)
Ray test special cases
![Page 16: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/16.jpg)
Point in convex polygon
(y - y0) (x1 - x0) - (x - x0) (y1 - y0)
> 0, point is to the left of the line< 0, point is to the right of the line= 0, point is on the line
![Page 17: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/17.jpg)
Point in convex polygon
(y - y0) (x1 - x0) - (x - x0) (y1 - y0) For (3,1):(1)(5) – (3)(0) = 5
For (3,0):(0)(5) – (3)(0) = 0
For (3,-1):(-1)(5) – (3)(0) = -5
![Page 18: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/18.jpg)
Polygon Intersection
Contained vertex Intersecting edges
![Page 19: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/19.jpg)
Polygon intersection – vertex + edges
![Page 20: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/20.jpg)
Collision detection: point-ground plane
0y
0y
0y
p = (x, y, z)
![Page 21: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/21.jpg)
Surface/Polygon normals
Images from http://en.wikipedia.org/wiki/Normal_(geometry)
![Page 22: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/22.jpg)
Collision detection: point-plane
dpNdczbyaxpE )(
0)( pE
0)( pE
0)( pEN
N = (a, b, c)
p = (x, y, z)
Terms:p = pointN = normal vectorD = distance from origin
![Page 23: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/23.jpg)
Collision detection: time of impact
2 optionsConsider collision at next time stepCompute fractional time at which collision actually occurred
Tradeoff: accuracy v. complexity
P(ti)
P(ti+1)
![Page 24: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/24.jpg)
3D object collision detection
![Page 25: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/25.jpg)
Collision detection: polyhedra
• Order tests according to computational complexity and power of detection
2. test for vertex of one object inside of other object
1. test bounding volumes for overlap
3. test for edge of one object intersecting face of other object
![Page 26: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/26.jpg)
Polygon and polyhedra complexity
How many edges? How many points?
![Page 27: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/27.jpg)
Bounding objects
• Sphere
• Axis aligned bounding box
• Oriented bounding box
![Page 28: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/28.jpg)
Bounding volume construction
• Given a set of points as input, can we automatically create bounding volumes
– Axis aligned bounding box
– Sphere
– Convex hull
![Page 29: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/29.jpg)
Axis aligned bounding box
![Page 30: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/30.jpg)
Axis aligned bounding box
![Page 31: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/31.jpg)
Bounding sphere
![Page 32: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/32.jpg)
Bounding sphere
![Page 33: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/33.jpg)
Bounding sphere
![Page 34: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/34.jpg)
Bounding sphere
![Page 35: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/35.jpg)
Convex HullBest fit convex polyhedron to concave polyhedron but takes some (one-time) computation
1. Find highest vertex, V12. Find remaining vertex that minimizes angle
with horizontal plane through point. Call edge L3. Form plane with this edge and horizontal line
perpendicular to L at V14. Find remaining vertex that for triangle that
minimizes angle with this plane. Add this triangle to convex hull, mark edges as unmatched
5. For each unmatched edge, find remaining vertex that minimizes angle with the plane of the edge’s triangle
![Page 36: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/36.jpg)
Convex hull
![Page 37: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/37.jpg)
Convex hull
![Page 38: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/38.jpg)
Convex hull
![Page 39: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/39.jpg)
Convex hull
![Page 40: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/40.jpg)
Convex hull
![Page 41: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/41.jpg)
Convex hull
![Page 42: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/42.jpg)
Convex hull
![Page 43: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/43.jpg)
Bounding SlabsFor better fit bounding polyhedron: use arbitrary (user-specified) collection of bounding plane-pairs
Is a vertex between each pair?
12 dPNd
![Page 44: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/44.jpg)
Sphere vs. Sphere
Compare distance (p1,p2) to r1+r2
distance(p1,p2)2 to (r1 + r2)2
![Page 45: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/45.jpg)
AABB vs. AABB
![Page 46: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/46.jpg)
AABB vs. AABB
![Page 47: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/47.jpg)
Oriented bounding boxes and arbitrary polygons
• Separating axis theorem– http
://gamedev.tutsplus.com/tutorials/implementation/collision-detection-with-the-separating-axis-theorem/
– http://www.sevenson.com.au/actionscript/sat/– http://
www.metanetsoftware.com/technique/tutorialA.html
![Page 48: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/48.jpg)
Sphere vs. AABB
![Page 49: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/49.jpg)
Sphere vs. AABB – clamping
![Page 50: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/50.jpg)
Sphere vs. AABB – closest point
![Page 51: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/51.jpg)
Collision detection: swept volumeTime & relative direction of travel sweeps out a volumeOnly tractable in simple cases (e.g. linear translation)
If part of an object is in the volume, it was intersected by object
![Page 52: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/52.jpg)
Collision detection: polyhedra
2. test for vertex of one object inside of other object
1. test bounding volumes for overlap
3. test for edge of one object intersecting face of other object
![Page 53: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/53.jpg)
Collision detection: polyhedra
Intersection = NOFor each vertex, V, of object A
if (V is inside of B) intersection = YESFor each vertex, V, of object B
if (V is inside of A) intersection = YES
A vertex is inside a convex polyhedron if it’s on the ‘inside’ side of all faces
A vertex is inside a cancave polyhedron if a semi-infinite ray from the vertex intersects an odd number of faces
![Page 54: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/54.jpg)
Collision detection: polyhedra
Edge intersection face testFinds all polyhedral intersections,but is the most expensive test:for all faces (i) for all edges (j) test face i for intersection with edge j
If vertices of edges are on opposite side of plane of faceCalculate intersection of edge with planeDetermine if that point of intersection is inside the face
![Page 55: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/55.jpg)
Collision detection speedup
![Page 56: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/56.jpg)
Particle collision detection loop
ArrayList Particles = new ArrayList();Particle p;Particles.Add(p);…
void HandleAllParticleCollisions(){for(int i=0; i < Particles.Count; i++){
for(int j ) {// test Particles i and j for collision
}}
}
=i+1 j < Particles.Count; j++
![Page 57: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/57.jpg)
Collision detection speedup
• Two approaches
– Bound the object
– Bound the space the object is contained in
![Page 58: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/58.jpg)
Hierarchical bounding volumes
Approximating polyhedra with spheres for time-critical collision detection, by Philip M. Hubbard
![Page 59: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/59.jpg)
HBV example
![Page 60: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/60.jpg)
HBV example
![Page 61: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/61.jpg)
HBV example
![Page 62: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/62.jpg)
Spatial subdivision – grid (quadtrees and octrees)
![Page 63: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/63.jpg)
Spatial subdivision – binary space partitioning
![Page 64: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/64.jpg)
Collision response
![Page 65: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/65.jpg)
Collisions: physics review
• Momentum• In a closed system, momentum is conserved
• After a collision, the sum of all momentums is the same as the sum of all momentum before the collision
mvp
''vmmvp
![Page 66: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/66.jpg)
Collision typesElastic collisions – no loss of kinetic energy (e.g. deformations, heat)
Inelastic collisions – loss of kinetic energy
2
2
1mvE Kinetic energy
![Page 67: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/67.jpg)
Elastic collision with stationary object: horizontal and vertical walls/planes
• For vertical wall/boundary– Negate x component of
velocity– Preserve y component of
velocity
• Ex: v0 = (3,-3) ; v = (-3,-3) • For horizontal
walls/boundaries– Preserve x– Negate y
![Page 68: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/68.jpg)
Elastic collision with stationary object: angled walls/planes
• Still split velocity vector into components– Now with respect to the normal
(n) of the wall
• u = (v * n / n * n) n– Note: * is dot product– Vector/direction is parallel to n– Scalar/magnitude is in opposite
direction of n; (v * n) < 0
• w = v – u• Reflected velocity: v’ = w – u
![Page 69: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/69.jpg)
Elastic collision with movable object
![Page 70: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/70.jpg)
Inelastic Collisions
Objects stick together,momentum is conserved
Coefficient of restitution ratio of velocities before and after collision (dampen the resulting velocity)
![Page 71: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/71.jpg)
Collision response: damped
Damping factor = 0.8
![Page 72: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/72.jpg)
Collision response – penalty method
![Page 73: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/73.jpg)
Collision response: penalty
![Page 74: Collision handling: detection and response](https://reader036.vdocuments.mx/reader036/viewer/2022062422/5681360c550346895d9d827d/html5/thumbnails/74.jpg)
Additional issues
• Adding physics for rotation• Handling multiple collisions
• Resting contact