Collision handling: detection and response
Collision handling overview Detection Discrete collision detection Convex polygon intersection test General polygon intersection test Continuous collision detection Vertex triangle test Edge edge test Response Kinematic response Penalty method
Discrete Collision Handling Run the simulation from t to t+1, without considering collision Check if any intersection happens at t+1 If so, remove it
Geometric Modeling Primitives Point Line segment Polygon
Terminology convex and concave polygons
Edge Test Decides convex/concave Always on one side Not always on one side Works same for convex/concave polyhedra (always on on side of the polygonal face?)
An important property of Convex polygons! Initial Pair You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex polygons! You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex polygons! You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex polygons! You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex polygons! You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex polygons! You can always find the closest vertex pair by gradually moving one vertex at each time!
An important property of Convex 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 polygons! The computational cost depends on the initial pair Worst case O(N) Best case O(1)! In animation, since we can keep the pair over time and the object movement within a time step is small, the initial pair is often good! O(1) Problem: not everything is convex Solution: decompose them into convex components Doesn t always work
General Polygon Intersection Tests To test whether two polygons intersect, we can To 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 the intersections! Odd => inside; even =>outside 3 intersections > inside
Inside/Outside Test To test whether a point is within a polygon/polyhedron, shoot a ray and count the intersections! Odd => inside; even =>outside 1 intersection > inside
Inside/Outside Test To test whether a point is within a polygon/polyhedron, shoot a ray and count the intersections! Odd => inside; even =>outside 4 intersection > > outside
Inside/Outside Test To test whether a point is within a polygon/polyhedron, shoot a ray and count the intersections! Odd => inside; even =>outside 0 intersection > outside
Inside/Outside Test Doesn t always work 2 intersections but still inside? This is called a degenerate case. Solutions? Try some other directions 2 intersections???
Problem 1 (in 3D)? Collision can happen even there is no vertex inside of the other polyhedron. Called edge edge colllision The solution requires complex intersection tests. We skip it here
Discrete Collision Handling Run the simulation from t to t+1, without considering collision 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 between. Time 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 g discrete collision detection).
For example: Vertex Triangle Test Four points P 0 (t)=p 0 +tv 0 ; P 1 (t)=p 1 +tv 1 ; P 2 (t)=p 2 +tv 2 ; P 3 (t)=p 3 +tv 3 Intersection happens when they are co planar (P 1 (t) P 0 (t)) (P 2 (t) P 0 (t)) (P 3 (t) P 0 (t))=0 Once you find t, verify if P 0 0( (t) is within the triangle. P1 P2 P0 P3
For example: Edge EdgeTestEdgeTest Four points P 0 (t)=p 0 +tv 0 ; P 1 (t)=p 1 +tv 1 ; P 2 (t)=p 2 +tv 2 ; P 3 (t)=p 3 +tv 3 Intersection happens when they are co planar (P 1 (t) P 0 (t)) (P 2 (t) P 0 (t)) (P 3 (t) P 0 (t))=0 Once you find t, verify if they do intersect! P1 P2 P0 P P3
Polygon and polyhedra complexity How many edges? How many points?
Bounding objects Sphere Axis aligned bounding box Oriented bounding box
Bounding volume construction Given a set of points as input, can we automatically create bounding volumes Axis aligned bounding box Sphere Convex hull
Axis aligned bounding box
Axis aligned bounding box (AABB)
Bounding sphere
Bounding sphere
Bounding sphere
Bounding sphere
Convex Hull Best fit convex polyhedron to concave polyhedron but takes some (one-time) computation 1. Find highest vertex, V1 2. Find remaining vertex that minimizes angle with horizontal plane through point. Call edge L 3. Form plane with this edge and horizontal line 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 unmatched thd 5. For each unmatched edge, find remaining vertex that minimizes angle with the plane of the edge s triangle 6. 3D convex hull is more complex
Convex hull
Convex hull
Convex hull
Convex hull
Convex hull
Convex hull
Convex hull
Bounding Slabs For better fit bounding polyhedron: use arbitrary (user-specified) collection of bounding plane- pairs Is a vertex between each pair? d N P 2 d 1
Sphere vs. Sphere Compare distance (p 1,p 2 ) to r 1 +r 2 distance(p 1,p 2 ) 2 to (r 1 + r 2 ) 2
AABB vs. AABB
AABB vs. AABB
Oriented bounding boxes and arbitrary polygons Separating axis theorem http://gamedev.tutsplus.com/tutorials/implement ation/collision detection with the separating axis the separating axis theorem/ http://www.sevenson.com.au/actionscript/sat/ http://www.metanetsoftware.com/technique/tut oriala.html
Hierarchical bounding volumes Approximating polyhedra with spheres for time critical collision detection, by Philip M. Hubbard
HBV example
HBV example
HBV example
Spatial subdivision grid (quadtrees and octrees)
Spatial subdivision binary space partitioning ii i
Collision response
Collisions: physics review Momentum p mv In a closed system, momentum is conserved p mv m'v' After a collision, the sum of all momentums is the same as the sum of all momentum before the collision
Collision types Elastic collisions no loss of kinetic energy (e.g. deformations, heat) Inelastic collisions loss of kinetic energy Kinetic energy 1 E mv 2 2
Elastic collision with stationary object: horizontal and vertical walls/planes l For vertical wall/boundary a/bouday Negate x component of velocity Preserve y component of velocity Ex: v 0 = (3, 3) ; v = ( 3, 3) For horizontal walls/boundaries Preserve x Negate y
Elastic collision with stationary object: 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 angled ldwalls/planes l
Inelastic Collisions Coefficient of restitution ratio of velocities before and after collision (dampen the resulting velocity) Objects stick together, momentum is conserved
Collision response penalty method