CS599 Physically Based Modeling for Interactive Simulation and Games 02/17/10 Collision Detection Book: Real time collision detection By Christer Ericson Good research for collision detection: University of North Carolina, Chapel Hill * Brute Force collision detection * Classes of objects and problems in collision detection * Two-Phase collision detection: Broad Phase and Narrow Phase * Gilbert-Johnson-Keerthi Algorithm ================================================================================================ Basic collision detection Given 2 objects (triangle meshes / volumes / bi-splines / curves / nurbs), check if they intersect by using the separation distance d. If they intersect, calculate the penetration depth. If we know the separation distance, we can predict collision detection. If we know the penetration depth, we can apply penalty methods. Brute Force collision detection Given two objects having n triangle meshes, compare every two triangles. Complexity would be O(n*n). Classes of objects and problems in collision detection ------------------------------------------------------ * 2D v/s 3D * convex v/s non-convex convex->simple, non-convex->harder An object is convex if for every pair of points within the object, every point on the straight line segment that joins them is also within the object. For non-convex objects, the idea is to break the object into convex objects and for each individual pair check collision detection. If there are n vertices and faces in a non-convex object, you can break it up into n*n pieces. * Polygonal v/s non-polygonal (curves / nurbs) * Open surfaces v/s closed surfaces * Rigid v/s non-rigid If object deforms, collision detection becomes much harder. * Pairwise v/s multiple * CSG v/s B-rep Constructive solid geometry (CSG) is a way to model objects. We can perform unions,intersections or any mathematical operators on geometries like cubes, cylinders, spheres, cones etc to build complex objects. * Static v/s dynamic ------------------------------------------------------------------------------------------------ Broad Phase and Narrow Phase Collision Detection Suppose there are N objects in the scene. We first apply Broad Phase and create a list of objects colliding. Then we run Narrow Phase which includes methods like convex methods or boundary volume hierarchy. But narrow phase methods are expensive so one must avoid NP as more as possible. Broad Phase Algorithms ---------------------- 1. Spatial Subdivision: create grids/box that covers all objects. Check in which boundary/box the object lies. This takes O(1) time. For n objects it will take O(n) time which is very much faster than the O(n*n) for brute force. Pass all the pairs in the list to narrow phase. Issues: Selection of size of grid. Solution: Adaptive: Octrees Linear octrees is an example which uses morton index. Another way is to use kd trees which are d dimensional trees. Hybids: Using hash table to store cells that are non-empty. Narrow Phase Algorithms ----------------------- The Gilbert-Johnson-Keerthi (GJK) Algorithm -------------------------------------------- Given two convex polyhedra, computes distance d (shortest distance between the two polygons) and can also return closest pair of points Pa and Pb. Separating plane theory: Any two non-penetrating convex objects can be separated by a plane. This theory forms a foundation for many algorithms for convex objects. The theorem fails for nonconvex objects. THE GJK Algorithm: Terminologies ------------- The support mapping function for a convex polyhedron simply returns the vertex most distant in direction d (any one if several equally distant). The support mapping for a sphere C of radius r and center O is given by SC(d) = O + r * ||d||. A d-simplex is the convex hull of d+1 affinely independent points in d-dimensional space. A simplex (plural simplices) is a d-simplex, for some given d The convex hull of a set C of points is here denoted by CH(C). Algorithm --------- * Initialize the simplex set Q (Q=Q0,Q1,Q2) with up to 3 points from C (in 2 dimension) * Compute point P of minimum norm in CH(Q) * If P is the origin, exit; return 0 * Reduce Q to the smallest subset Q’ of Q, such that P in CH(Q’) * Let V=SC(–P) be a supporting point in direction –P * If V no more extreme in direction –P than P itself, exit; return ||P|| * Add V to Q. Go to step 2