Visual Interactive Simulation, TDBD24, Spring 2006 Lecture 6 Outline Cross product as matrix multiplication The collision matrix The Newton Coulomb impulse for rigid bodies N C updates of translational and rotational velocities Multiple contact points An iterative solver (for lab 3 4) Next lecture... Intersection of convex polyhedra Separating axis theorem Intersection points for oriented bounding boxes (OBB) Cross product as matrix multiplication The cross product is defined as, a =(a i,a j,a k ), b =(b i,b j,b k ) i j k a b = a i a j a k b i b j b k =(a jb k b j a k,a k b i b k a i,a i b j b i a j ) Assume we could write this as a matrix product instead, a b = a b The special construct, the cross product matrix, a, that allows this is, a = 0 a z a y a z 0 a x a y a x 0 1
The collision matrix The collision matrix is mainly a way to compactify notation. An impulse will change the center of mass velocities as, v A,B = v A,B +/ J/m A,B It will also change the angular velocities, ω A,B = ω A,B +/ I 1 A,B(r A,B x J) The new velocities at the collision points thus are, u A,B = u A,B +/ (J/m A,B + (I 1 A,B(r A,B x J)) x r A,B ) = u A,B +/ (1/m A,B r A,Bx I 1 A,B r A,B x ) J The collision matrix Thus, the change in the relative collision velocity is, u = u u = (u A u B ) (u B u A ) u = (1/m A + 1/m A (r Ax I 1 A r A x + r Bx I 1 B r B x) ) J which can be written as, u = K J where K is called the collision matrix. 2
Newton Coulomb impulses for rigid bodies First we assume sticking, with zero tangential velocity after the impact, that is, u t = 0 u n = e u n Given that u = u u, we can write the impulse as, J = K 1 (u u) We can compute normal and tangential components of J J n = (J n) n J t = J J n The tangential friction is reactive and depends on the normal force. Sticking requires that, J t J n Otherwise we must consider sliding friction. (identical with the max(...) clamping law in previous lectures look it up and compare!). Newton Coulomb impulses for rigid bodies For sliding, we first determine the direction of sliding, u n = (u n) n u t = u u n Now we can compute the sliding unit vector, t = u t / u t Next, we define the sliding impulse to be, J = j n µ j t (i.e. J n = j n) 0 µ 1 is the friction coefficient. 3
Newton Coulomb impulses for rigid bodies Thus, we know an expression for the impulse how this impulse changes the collision velocity how the normal velocity changes due to Newton s impact law Take the dot product of u = u u = K J with the collision normal n, u n = u n + n T K J Use Newton s impact law u n = e u n e u n = u n + n T K J Newton Coulomb impulses for rigid bodies Rearrange and insert the expression for J, (1+e)u n = n T K(jn µ j t) Finally we solve for j, to compute the unknown impulse. (1+e)u n = n T K(n µ t) j j = (1+e)u n / n T K(n µ t) Knowing j, we can compute the impulse, and Thus the new post collision translational and rotational velocities of body A and B, respectively! 4
Review NC Rigid Body Collisions (Broad phase collision detection) Narrow phase collision detection List of intersections Compute collision velocity Check if colliding, resting or separating If colliding, compute the NC impulse Update translational (CoM) and rotational velocity... add external forces, handle contacts, time integrate, render... J 0 impulse Multiple simultaneous contacts/collisions E.g. Rigid body stacking. N bodies Solve using 2 body interaction Frequency/wavelength limitation An impulse travels at 1 body/timestep that is 1 body/ It takes M timesteps to travel through M bodies Spooongy! We need something that works at the speed of sound, i.e. ~ 1000 m/s If 1 body ~ 0.1 m, then we must propagate 10000 bodies/s or ~ 167 bodies/timestep thus a 167 body method!! Trend: An approximate solver solves just about this! More brutal approximations enable stacks of up to thousands of bodies to be simulated in real time. Typically these use an iterative methods that boils down to Gauss Seidel. 5
Bottom up iterative impulse solver Basic idea: During each timestep loop through the collision set and solve collisions pair wise, and hope that for each pass/iteration, there will be fewer and/or smaller collisions, until they are eventually all resolved... Treat collisions and contacts in a similar way (i.e. compute an impulse) Each iteration will propagate impulses one body through the system (i.e. we would need ~167 iterations in previous example). Many tricks (and problems): How to choose the order of when you loop through the collision set?! How to avoid cycles (i.e. non convergence)?! A top down method? Can be formulated from a matrix/algebraic formulation of the rigid body problem i.e. the algorithm can actually be derived and better understood, whereas it is more like invented in this bottom up approach. Bridson, Guendelman, Fedkiw method Guendelman, E., Bridson, R. and Fedkiw, R., ʺNonconvex Rigid Bodies with Stackingʺ, SIGGRAPH 2003, ACM TOG 22, 871 878 (2003). http://graphics.stanford.edu/papers/rigid_bodies sig03/ Follow ups: Weinstein, R., Teran, J. and Fedkiw, R., ʺDynamic Simulation of Articulated Rigid Bodies with Contact and Collisionʺ, IEEE TVCG, (in press). http://graphics.stanford.edu/~rachellw/prestabilization.html D. M. Kaufman, T. Edmunds, and D. K. Pai, ``Fast Frictional Dynamics for Rigid Bodiesʹʹ in Proceedings of ACM SIGGRAPH 2005, Aug 2005. http://www.research.rutgers.edu/~kaufman/ffdfrb.html Very much inspired by previous work by, Hahn, Steward, Mirtich and many others. See text book for more references. 6
Bridson, Guendelman, Fedkiw method Bridson, Guendelman, Fedkiw method Uses Newton Coulomb impulses. Separates collisions from contacts and treats them separately in a cleaver way! In it s simplest version reuses original collision set throughout the timeset. Uses shock propagation and a pre determined direction (gravity) to avoid loops and minimize errors. Ends with a position correction method that attempts to remove overlaps that still exist after the approximate solver has delivered. 7
Bridson, Guendelman, Fedkiw method Algorithm: 1. Find intersections 2. Flag non separating intersections 3. Collision loop over non separating intersections i. Loop sequentially over rigid body pairs, and their non separating points, resolving the collisions, by instantaneously updating translational and angular velocity, and linear and angular momentum. ii. After each full pass through the non separating set, remove all points that now are separations. iii. Repeat N times (N= ~ 5 15) 4. Add external forces, i.e. gravity, air friction, and time integrate the linear and angular momentum, linear and angular velocities. Do not update positions yet! 5. From the previous iteration, there may still be un resolved collisions that must be resolved. In addition teh velocity integration (e.g. gravity) will have introduced new collisions. Thus, flag all non separating contacts in the original contact set. These will now all be treated as resting contacts. 6. Collision loop over non separating intersections to put them to rest i. Loop over bodies, and their non separating contacts to compute NC impulses and new velocities. Each pass through all non separating contacts is one iteration. ii. Start with a negative restitution e = 1 and for each iteration gradually take it down to 0 (e.g. 0.8 0.6 0.4 0.2 0.0 for 5 iterations). Thus we will slowly damp the collision and finally put it to rest (provided the algorithm actually converges. Use N ~ 10 20 iterations. 7. Use our new velocities and time integrate for new positions. 8. Check the original contact set (from 2). If these are still overlapping, then do a position correction loop on these contact pairs: i. Sometimes called first order physics. Instead of computing an impulse, simply loop through the contact pairs, and separate them along the normal so that the penetration depth becomes zero. Let the separation be inversly proportional to the mass of the body, so that lighter bodies are moved further than heavy bodies (i.e. a fixed plane doesn t move at all). ii. Since contact pair are dependent, repeat also this process with an iterative loop. In the first step only separate a fraction of the penetration depth, in the second, separate more, etc. So that the last iteration attempts to do a complete separation. Use ~5 10 iterations. 8