Collision handling:detection and response
Collision handling overview
Discrete collision detectionConvex polygon intersection testGeneral polygon intersection test
DetectionContinuous collision detection
Vertex‐triangle testEdge‐edge test
Kinematic responseR
Penalty methodResponse
Discrete Collision Handlingg
• Run the simulation from t to t+1 withoutRun the simulation from t to t+1, without considering collision
• Check if any intersection happens at t+1• Check if any intersection happens at t+1• If so, remove it
Geometric Modeling Primitivesg
• PointPoint
• Line segment
• Polygon
Terminology – convex and concave lpolygons
Edge Test Decides convex/concave
Always on one side Not always on one sideAlways on one side Not always on one side
Works same for convex/concave polyhedra (always on on side of the polygonal face?)(always on on side of the polygonal face?)
An important property of Convex l !polygons!
Initial Pair
You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex l !polygons!
You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex l !polygons!
You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex l !polygons!
You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex l !polygons!
You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex l !polygons!
You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex l !polygons!
No more improvement, done!
You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex l !polygons!
• The computational cost depends on the initial pair– Worst case O(N)B t O(1)!– Best case O(1)!
• In animation, since we can keep the pair over time and the object movement within a time step isand the object movement within a time step is small, the initial pair is often good!– O(1)O(1)
• Problem: not everything is convex– Solution: decompose them into convex componentsp p– Doesn’t always work
General Polygon Intersection Tests
• To test whether two polygons intersect, we canTo test whether two polygons intersect, we can test whether any vertex is inside of another
Inside/Outside Test
• To test whether a point is within a polygon/polyhedron shoot a ray and count thepolygon/polyhedron, shoot a ray and count the intersections!
• Odd => inside; even =>outside• Odd => inside; even =>outside
d3 intersections ‐> inside
Inside/Outside Test
• To test whether a point is within a polygon/polyhedron shoot a ray and count thepolygon/polyhedron, shoot a ray and count the intersections!
• Odd => inside; even =>outside1 intersection ‐> inside
• Odd => inside; even =>outside
Inside/Outside Test
• To test whether a point is within a polygon/polyhedron shoot a ray and count thepolygon/polyhedron, shoot a ray and count the intersections!
• Odd => inside; even =>outside• Odd => inside; even =>outside
4 intersection > outside4 intersection ‐> outside
Inside/Outside Test
• To test whether a point is within a polygon/polyhedron shoot a ray and count thepolygon/polyhedron, shoot a ray and count the intersections!
• Odd => inside; even =>outside• Odd => inside; even =>outside
0 intersection ‐> outside
Inside/Outside Test• Doesn’t always work…• 2 intersections but still inside?intersections but still inside?• This is called a degenerate case. • Solutions? Try some other directionsSolutions? Try some other directions
2 intersections???
Problem 1 (in 3D)?( )
Collision can happen even there is no vertex inside of ppthe other polyhedron. Called edge‐edge colllision
The solution requires complex intersection tests. We skip it here…
Discrete Collision Handlingg
• Run the simulation from t to t+1 withoutRun the simulation from t to t+1, without considering collision
• Check if any intersection happens at t+1• Check if any intersection happens at t+1• If so, remove it
Problem 2?• Discrete collision handling has a tunneling artifact.• No intersection at t or t+1, but intersection happens in‐No intersection at t or t , but intersection happens inbetween.
Time t Time t+1Time t Time t+1
Problem 3?
• To do inside/outside test, the object must be closed.• In other words, it has an area (or volume).• How do I know if two curves/surfaces are intersecting?
– Knowing the location of the intersection is not sufficient!
Solution• We don’t just check whether intersection happens at t or t+1.
• We check if any intersection happens between t and t+1.• This is called continuous collision detection (opposing to ( pp gdiscrete collision detection).
For example: Vertex‐Triangle TestFor example: Vertex Triangle Test• Four points
– P0(t)=P0+tV0; P1(t)=P1+tV1; P2(t)=P2+tV2; P3(t)=P3+tV3
• Intersection happens when they are co‐planarpp y p– (P1(t)‐P0(t))(P2(t)‐P0(t))×(P3(t)‐P0(t))=0
• Once you find t, verify if P0(t) is within the triangle.y , y 0( ) g
P1P2
P0
P1
P3
For example: Edge‐EdgeTestFor example: Edge EdgeTest• Four points
– P0(t)=P0+tV0; P1(t)=P1+tV1; P2(t)=P2+tV2; P3(t)=P3+tV3
• Intersection happens when they are co‐planar– (P1(t)‐P0(t))(P2(t)‐P0(t))×(P3(t)‐P0(t))=0
• Once you find t, verify if they do intersect!Once you find t, verify if they do intersect!
P2
P0
P1
PP0 P3
Polygon and polyhedra complexityPolygon and polyhedra complexity
How many edges? How many points?
Bounding objectsBounding objects
• SphereSphere
• Axis aligned bounding box• Axis aligned bounding box
• Oriented bounding box
Bounding volume constructionBounding volume construction
• Given a set of points as input can weGiven a set of points as input, can we automatically create bounding volumes
– Axis aligned bounding box
– Sphere
– Convex hull
Axis aligned bounding boxAxis aligned bounding box
Axis aligned bounding box (AABB)Axis aligned bounding box (AABB)
Bounding sphereBounding sphere
Bounding sphereBounding sphere
Bounding sphereBounding sphere
Bounding sphereBounding sphere
Convex HullConvex HullBest fit convex polyhedron to concave polyhedron but takes some (one-time)polyhedron but takes some (one time) computation
1. Find highest vertex, V12. Find remaining vertex that minimizes angle
Cwith horizontal plane through point. Call edge L
3. Form plane with this edge and horizontal line perpendicular to L at V1line perpendicular to L at V1
4. Find remaining vertex that for triangle that minimizes angle with this plane. Add this triangle to convex hull, mark edges as
t h dunmatched5. For each unmatched edge, find remaining
vertex that minimizes angle with the plane of the edge’s triangleg g
6. 3D convex hull is more complex…
Convex hullConvex hull
Convex hullConvex hull
Convex hullConvex hull
Convex hullConvex hull
Convex hullConvex hull
Convex hullConvex hull
Convex hullConvex hull
Bounding SlabsFor better fit bounding polyhedron: use arbitrary (user-specified) collection of bounding plane-
ipairsIs a vertex between each pair?
12 dPNd 12
Sphere vs. SphereSphere vs. Sphere
Compare distance (p1,p2) to r1+r2distance(p1,p2)2 to (r1 + r2)2
AABB vs. AABBAABB vs. AABB
AABB vs. AABBAABB vs. AABB
Oriented bounding boxes and arbitrary lpolygons
• Separating axis theoremSeparating axis theorem– http://gamedev.tutsplus.com/tutorials/implementation/collision‐detection‐with‐the‐separating‐axis‐ation/collision detection with the separating axistheorem/
– http://www.sevenson.com.au/actionscript/sat/http://www.sevenson.com.au/actionscript/sat/– http://www.metanetsoftware.com/technique/tutorialA.html
Hierarchical bounding volumesHierarchical bounding volumes
Approximating polyhedra with spheres for time‐critical collision detection, by Philip M. Hubbard
HBV exampleHBV example
HBV exampleHBV example
HBV exampleHBV example
Spatial subdivision – grid ( d d )(quadtrees and octrees)
Spatial subdivision – binary space i i ipartitioning
Collision responseCollision response
Collisions: physics reviewCollisions: physics review
• Momentum mvp Momentum• In a closed system, momentum is conserved
mvp
''vmmvp
• After a collision, the sum of all momentums is the same as the sum of all momentum before the collision
Collision typesCollision typesElastic collisions – no loss of kinetic energy (e g deformations heat)
Inelastic collisions – loss of kinetic energyenergy (e.g. deformations, heat) kinetic energy
1 2
21 mvE Kinetic energy
Elastic collision with stationary object: h i l d i l ll / lhorizontal and vertical walls/planes
• For vertical wall/boundaryo e ca a /bou da y– Negate x component of
velocityP f– Preserve y component of velocity
• Ex: v0 = (3,‐3) ; v = (‐3,‐3) 0 ( , ) ; ( , )• For horizontal
walls/boundaries– Preserve x– Negate y
Elastic collision with stationary object: l d ll / langled 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 nVector/direction is parallel to n– Scalar/magnitude is in opposite
direction of n; (v * n) < 0• w = v – uw v u• Reflected velocity:
v’ = w – u
Inelastic Collisions
Coefficient of restitution ratio of velocities before andratio of velocities before and after collision (dampen the resulting
l it ) Objects stick together,momentum is conserved
velocity)
Collision response – penalty method