Collision Detection - Part 2 - Collision Detection Part 2 1...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Collision Detection Part 2 1 Sphere-Sphere Collision A sphere is represented using its center and its radius d Intersection if d is less than the sum of their two radius 2 How About 2 MOVING spheres? 2 spheres move during a time step from one point to another Their paths cross in-between but this is not enough to prove that an intersection occurred (they could pass at a different time) nor can the collision point be determined. 3 How About 2 MOVING spheres? Sliced time step up into smaller pieces. Move the spheres according to that sliced time step using its velocity, and check for collisions. If at any point collision is found (which means the spheres have already penetrated each other) then Take the previous position as the intersection point The smaller the time steps, the more slices we use the more accurate the method is. As an example lets say the time step is 1 and our slices are 3. We would check the two balls for collision at time 0 , 0.33, 0.66, 1. 4 Sphere-Plane Collision Determine the exact collision point between a particle and a plane. The start position of the ray is the position of the particle and the direction of the ray is its velocity (speed and direction). 5 Sphere-Plane Collision Each sphere has a radius, take the center of the sphere as the particle and offset the surface along the normal of each plane of interest. ones represented by continuous lines, but the collision testing is done with the offset primitives (represented with dotted lines). test with a little offset plane. Our actual primitives of interest are the In essence we perform the intersection 6 Sphere-Plane Collision Using this little trick the ball does not penetrate the surface if an intersection is determined with its center. where the sphere penetrates the surface. This happens because we determine the intersection between its center and the primitives. Otherwise we get the situation 7 Calculating Plane Equations A 3D Plane is defined by a normal and a distance along that normal Plane Equation: ( Nx, Ny, Nz ) ( x, y, z ) +d = 0 Find d: ( Nx, Ny, Nz ) ( Px, Py, Pz ) = -d For test point (x,y,z), if plane equation > 0: point on `front' side (in direction of normal), < 0: on `back' side = 0: directly on plane 8 Example: Distance to Plane A plane is described by a point p on the plane and a unit normal n. Find the distance from point x to the plane x n p 9 Example: Distance to Plane The distance is the length of the projection of x-p onto n: dist = ( x - p ) n n p x x-p 10 Collision Detection Two convex objects are non-overlapping/penetrating if there exists a separating plane between them separating plane So, find a separating plane and see if it is still valid after the next simulation step Speed up with bounding boxes, grids, hierarchies, etc Use bounding volumes (BV's) to approximate each object's real volume 11 Bounding Volumes? Reduce complexity of collision computation by substitution of the (complex) original object with a simpler object containing the original one. The original objects can only intersect if the simpler ones do. Or better: if the simpler objects do NOT intersect, the original objects won't either. 12 Bounding Volumes? Spheres, cylinders, boxes, polyhedra, etc. Spheres are mostly used For boxes and polyhedra, most intersection tests start with point insideoutside tests That's why convexity matters. 13 2D Point Inside-Outside Tests Convex Polygon Test Test point has to be on same side of all edges Concave Polygon Tests 360 degree angle summation Compute angles between test point and each vertex, inside if they sum to 360 Slow, dot product and acos for each angle! Other concave polygon tests are Quadrant Method or Edge Cross Test etc 14 Spheres as Bounding Volumes Simplest 3D Bounding Volume Center point and radius Point in/out test: Calculate distance between test point and center point If distance <= radius, point is inside It is ALWAYS worth it to do a sphere 15 test before any more complicated test. Sphere-Anything Testing The key observation is that collision testing with a sphere can be converted into a closest point problem: Given a point and an object, find the point on the object that is closest to the given point To test for collision with a sphere, find out if the point closest to the sphere's center is closer than the sphere's radius 16 Axis-Aligned Bounding Boxes Specified as two points: ( xmin , ymin , z min ), ( xmax , ymax , z max ) Simple point-inside test: xmin x xmax ymin y ymax z min z z max 17 Problems With AABB's Not very efficient Rotation can be complicated Must rotate all 8 points of box Other option is to rotate model and rebuild AABB, but this is not efficient 18 Oriented Bounding Boxes Center point, 3 normalized axis, 3 edge half-lengths Can become not-a-box after transformations Better at bounding than spheres and AABB's 19 OBB Point Inside/Outside Tests Plane Equations Test Plug test point into plane equation for all 6 faces If all test results have the same sign, the point is inside Smart Plane Equations Test Each pair of opposing faces has same normal, only d changes Test point against d intervals down to 3 plane tests 20 k-DOP's k-Discrete Oriented Polytype K is the number of the projected faces Set of k/2 infinite `slabs' A slab is a normal and a d-interval Intersection of all slabs forms a convex polyhedra OBB and AABB are 6-DOP's Same intersection tests as OBB There is an even faster test if all your objects have the same k and same slab normals Better bounds than OBB 21 Bounding Volumes K-DOP Easy to compute Good fill efficiency Simple overlap test Not invariant to rotation k-DOP is 22 Plane Intersection Tests Planes are good for all sorts of things Boundaries between level areas, `finish lines', track walls, etc Basis of BSP (Binary Space Partition) Trees Used heavily in game engines like Quake(1, 2,... They PARTITION space in half ) 23 AABB/Plane Test An AABB has 4 diagonals Find the diagonal most closely aligned with the plane normal Check if the diagonal crosses the plane 24 Other Plane-ish Tests Plane-Plane Planes are infinite. They intersect unless they are parallel. You can build an arbitrary polyhedra using a bunch of planes (just make sure it is closed....) Triangle-Triangle Many, many different ways to do this 25 Separating Axis Theorem For any two arbitrary, convex, disjoint polyhedra A and B, there exists a separating axis where the projections of the polyhedra for intervals on the axis and the projections are disjoint Lemma: if A and B are disjoint they can be separated by an axis that is orthogonal to either: 1) 2) 3) a face of A a face of B an edge from each polyhedron 26 Separating Axis Theorem Test Can also be used to determine intersection between objects: Sphere/AABB AABB/AABB OBB/OBB etc 27 OBB/OBB Geometric Test To check if A is intersecting B: Check if any vertex of A is inside B Check if any edge of A intersects a face of B Repeat tests with B against A Face/Face tests It is possible for two boxes to intersect but fail the vertex/box and edge/face tests. Catch this by testing face centroids against boxes Very unlikely to happen, usually ignored 28 Bounding volume schemes Schemes to detect collision on different scales: 1. Hierarchies of bounding volumes 2. Dimension reduction methods 3. Spatial hashing methods 29 Hierarchical Bounding Volumes To achieve higher exactness in collision detection, build a multiscale BV representation of the object. Sphere Trees, AABB Trees, OBB Trees Trees are built automagically Usually precomputed, fitting is expensive Accurate bounding of concave objects Down to polygon level if necessary 30 Bounding Volume Hierarchies The hierarchy is stored in a tree named by the underlying BV scheme : AABB-tree, OBB-tree, k-DOP tree, Sphere-tree Basic idea is to build a tree where each level of the tree bounds is its children Generally used for large numbers of static obstacles and a few moving things Put all the static obstacles into the tree Test for intersection between moving object and tree Intersection test looks a lot like testing against an octree or BSP tree The major difference is that a bounding volume hierarchy does not subdivide all of space, only those parts of space that are occupied Also used for subdividing a single object, as we will see later 31 Hierarchies 32 Hierarchies Recursive Collision Detection Returns TRUE if BBs overlap. How could this be improved to give a precise overlap test ? ) 33 Hierarchical Bounding Volumes 34 BVH vs Spatial Partitioning 35 Spatial Partitioning - Idea 36 Spatial Data Structures 37 Octree , k-d Tree 38 BSP-Tree binary space partitioning tree hierarchical structure space is subdivided by means of arbitrarily oriented planes generalized k-d tree space partitioning into convex cells discrete-orientation BSP trees DOBSP (finite set of plane orientations) 39 BSP Tree for Collision Detection 40 Collision Query 41 Dimension Reduction Algorithm works with AABBs In order for two AABBs to overlap in 3D, they must overlap along every 1D axis This is a special case of the separating plane theorem Sort the box extents in each dimension Find all the 1D overlaps Tag pairs that overlap in all dimensions (can be done without much overhead on the 1D problems) y x X overlaps: green-red, red-blue Y overlaps: orange-red,orange green, green-red, green-blue 2D overlaps: green-red 42 Exploiting Coherence Sometime you can claim that the sorted order of the bound extents will not change much between tests If objects don't move far in each frame, and don't frequently change direction This assumption fails for bouncing objects 43 Spatial Hashing Spatial hashing was developed to avoid the bouncing problem with dimension reduction Claims near linear time overlap detection Basic idea: Pretend space is broken up into a regular subdivision, but don't store the cells Determine the indexes of the cells that each bound overlaps Regular subdivision makes finding cell indices easy Turn the indexes into hash keys, one for each overlapped cell (just concatenate the bits) Hash the object into a table based on the keys Hash table collisions indicate overlaps 44 2D Spatial Hashing Orange is hashed into 0100 Green is hashed into 0100, 0000, 0101 and 0001 Red is hashed into 1001, 0101 Blue is hashed into 0101, 0110, 0001, 0010 Orange-green, green-red, green-blue, red-blue are all potential collisions 10 01 00 00 01 10 The problem with spatial hashing (like any regular grid technique) is choosing the grid resolution A good heuristic is that a cell should be about twice as large as the bounds 45 Dynamic Simulation Architecture Collision Detection is generally the bottleneck in any dynamic simulation system Lots of ways to speed up collisiondetection 46 Reducing Collision Tests Testing each object with all others is O(N2) At minimum, do bounding sphere tests first Reduce to O(N+k) with sweep-and-prune See SIGGRAPH 97 Physically Based Modelling Course Notes Spatial Subdivision is fast too Updating after movement can be complicated AABB is easiest to sort and maintain Not necessary to subdivide all 3 dimensions 47 Other neat tricks Raycasting Fast heuristic for `pass-through' problem Sometimes useful in AI Like for avoiding other cars Caching Exploit frame coherency, cache the last vertex/edge/face that failed and test it first `hits' most of the time, large gains can be seen 48 Collision Response What should happen when 2 object collide? It is a dynamic problem calculating the state (velocity, ...) after the collision Several approaches: 1. 2. 3. Projection Penalty-force Impulse-based 49 Projection The basic idea is to move the objects out of overlapping/penetrating using the smallest possible displacement i.e. need to find the vector v which moves the two objects out of penetration by the shortest distance possible. Modifies the position of objects directly 50 Penalty-force response Use spring forces to pull objects out of collision modify the acceleration of the object caused from the spring force 51 Impulse-based method Use instantaneous impulse (changing in velocity) to prevent objects from overlapping/penetrating Modify the velocity of the object 52 Application Examples Computer Games Medical Surgery 53 Bounding Volumes k-DOPs are used e.g. in the game `Cell Damage' (XBOX, Pseudo Interactive, 2002) 54 Bounding Volumes 3D Example: UNREAL-Engine 55 Intestinal Surgery small intestine colon Surgery objective - remove cancerous colon tissues Laparoscopic technique Critical task - move the small intestine aside Aim: Train the surgeons to do this task 56 Challenges Small Intestine 4 m length, 2 cm thick Mesentery Folded surface 15 cm width Connects intestine with main vessels Model the complex anatomy Detect multiple self-collisions Provide a stable collision response 57 Related Work Real-time deformable models - Multiresolution models [Capell02, Debunne01, Grinspun02] - Soft-tissue models [Cotin00, James99, James02, Meseure00] Objects in isolation or interacting with a rigid tool => Different Situation Skeletal model for intestine [France02] - Chain of masses and springs - Implicit surface representation for smooth rendering - 3D grids for self-collision and collision with environment Not applicable for mesentery Hierarchical BV detection [Bradshaw02, Cohen95, Gottschalk96, van den Bergen97] - Sphere-trees, OBBs, AABBs, etc. Expensive tree updates for large-scale deformation 58 References Real-time Simulation of Self-Collisions for Virtual Intestinal Surgery, Raghupathi et al. (2003), IS4TM, France Rolf Lakaemper, Game Programming, Lecture Notes Others - later 59 ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online