Physically Based Modeling CS 15-863 Notes Spring 1997 Particle Collision and Contact 1 Collisions with Springs Suppose we wanted to ipleent a particle siulator with a floor : a solid horizontal plane which particles could bounce off of, or lie on. Assuing all the particles started out above the floor, they d all have to stay there for the rest of the siulation. How could we go about ipleenting this? Clearly, there are two probles. We need to detect when particles are near the floor, and when they are, we need to do soething to stop the fro passing through the floor. One obvious thing to do is to ipose a vertical spring force of ky(t) whenever the y-coordinate y(t) of the particle is less than zero. (We ll suppose the floor is siply the line y = 0.) If we ake k large enough, than we can prevent the particle fro oving too far beneath the floor. The proble is, that by aking k large, we set ourselves up for stiff ODE s, as entioned in earlier notes. Also, no atter what value of k you pick, I can always choose a heavy enough particle (or a particle oving downwards with a high enough velocity) so that the upwards ky(t) spring-force isn t strong enough to stop the particle fro oving substantially below the line y = 0. Of course, we could odify the spring force to copletely stop the particle fro oving below the floor, no atter what we throw at it. Suppose the spring force is e 1 ky(t) 2 ky(t). Then as y(t) 1 decreases towards zero, the spring force becoes strong quickly; in fact, it is ipossible for the particle to ever attain y(t) = 0 given this spring force. Note that in this case we have action at a distance : the spring force acts even before y(t) becoes negative. By aking k large though, we can ake the force fall off for positive values of y(t) quickly. Of course, this is a pretty stiff force function; ky(t) is a walk in the park in coparison... 2 Ipulses For both the linear springs and the exponential springs, as we increase k we cause the particle s velocity to change ore quickly. If we view our floor as an ipenetrable obstacle, we should just take this process to the liit, and let the particle undergo an instantaneous change in velocity. As an exaple, suppose we have a particle of ass and velocity v 0 (a vector). Lets apply a force F to the particle for a period of tie t. We ll assue that F points directly opposite to v 0, and that no other forces act on the particle. The particle s velocity v 1 tie t later is v 1 = t 0 F/dt+v 0 = F t +v 0 Suppose we want the force F to copletely cancel the initial velocity v 0 after tie t. Setting 1
v 1 to zero and solving, we get F = v 0 t (again under the assuption that F is directly opposite v 0 ). Clearly, to stop the particle instantaneously (that is, with t = 0) requires an infinite force. We can stop the particle arbitrarily quickly, by aking F suitably strong, but we can t stop the particle instantaneously with a force F. Instead, we ll define a new quantity called an ipulse. Lets iagine applying a force F over shorter and shorter tie intervals t. As tshrinks, F grows. Suppose that F grows without bound as t goes to zero, such that li t 0 F = in such a way that li F t t 0 converges to soe finite value J. The quantity J defined in such a way iscalled anipulse. Like force, ipulse is a vector quantity. Ipulse has the diensions of force ties tie, or equivalently, ass ties velocity. What is ipulse good for? Iagine that li t 0 F t = J = v 0 ; that is, no atter what t we choose, we pick F so that F t = v 0. Then as t goes to zero, we have v 1 = li t 0 t 0 F t F/dt+v 0 = li t 0 + v 0 = J/ + v 0 = 0. In the liit then, we have ade v 1 zero instantaneously. The idea of an ipulse is that when applied to a particle, it produces an instantaneous change of velocity. Unlike force, an ipulse is applied only for a zero-length period of tie. If we define the oentu P of a particle with ass and velocity v as P = v, then applying an ipulse J (of arbitrary direction) changes the oentu to P + J, and the velocity fro P/ to (P + J)/. Note that any other finite forces (e.g. gravity, wind) are ignored when an ipulse is applied, because the effects of these finite forces on the velocity go to zero as t goes to zero. By defining ipulses, we can abstractly consider the idea of an instantaneous change of velocity, by ignoring the continuous change of velocity that occurs over an arbitrarily sall tie interval t. 3 Collisions with Planes Lets apply the concept of an ipulse to let our particles bounce off an arbitrary plane. First, we need to worry about detecting collisions between a particle and a plane. Consider a particle with position x(t) in space, and a plane with a unit noral ˆn. The noral ˆn is chosen so that ˆn points towards the legal side of the plane. (For the case of the floor, ˆn points straight up.) Let q 0 be any point on the plane. Then the plane is defined as the set of points p such that ˆn ( p q 0 ) = 0. Our particle is on the legal side of the plane as long as ˆn (x(t) q 0 )>0. When ˆn (x(t) q 0 ) = 0, the particle has collided with the plane (figure 1). Deterining exactly when the particle has collided is in general a hard proble. Our approach will be as follows: whenever we find the particle is on the illegal side of the plane, we ll displace it in the ˆn direction so its exactly on the plane. Then we ll apply an ipulse to it to kick it away fro the wall. The correct way to do collision detection is explained in section 3.3. 2
q 0 p 2 v ( v N )ˆ n p 1 (illegal side) x(t) ˆ n Figure 1: The vector p 1 q 0 is opposite ˆn,so(p 1 q 0 ) ˆn<0andp 1 is on the illegal side of the plane. Siilarly, ( p 2 q 0 ) ˆn > 0. 3.1 Collision Response Our particle is in contact with the plane. What ipulse J should we apply to the particle to kick it off the wall? First, soe notation. Lets let the initial velocity, before application of J, bev. Lets let the velocity after application of J be v +. Define the noral speed v N before the collision (figure 1) by and the noral speed v N after the collision by v N =ˆn v v + N =ˆn v +. Note that v and v + are vectors while v N and v+ N are scalars. To deterine J, we use an epirical law for collisions. The law states that a collision can be described intersof acoefficient of restitution denoted by ɛ, where 0 ɛ 1. The law relates the initial noral speed to the final noral speed by v + N = ɛv N. (1) If ɛ = 1, then the noral speed is copletely reversed, and we have in effect a superball. Ifɛ = 0, the collision is copletely dead, in that the particle won t bounce away fro the wall. We can use this law to deterine J as follows. Assue that there is no friction between the particle and the wall. Then the direction of J is parallel to ˆn, and should be in the sae direction. 3
That is, we can write J = jˆnfor soe scalar j. Our intuition is that j should be a positive nuber. To copute j, we express v + N in ters of j and use equation (1). We have where is the particle s ass. Then v + = v + J = v + j ˆn v + N =ˆn v + =ˆn v +jˆn ˆn since ˆn ˆn = 1. Using equation (1), we get =v N + j which we can solve to obtain v + N = v N + j = ɛv N j = (1+ɛ)v N. Note that since we presuably started with v N being negative (since the particle had velocity partly opposite ˆn) weget j>0 as expected. If we want to add a frictional coponent, we can use a (siplified) version of Coulob s friction law. For any ipulse of strength j in the ˆn direction, there will also be an ipulse tangent to the plane of strength µj,whereµis the coefficient of friction. Reasonable values for µ would be in the range zero to perhaps 1. The direction of this tangential ipulse is directly opposite the coponent 3 of v in the plane. The coponent of v tangent to the plane is Thus, to add friction, let the total ipulse be v v N ˆn. j ˆn µj v v N ˆn v v N ˆn. (Don t try this if v has no tangential coponent.) 3.2 Particle/Plane Contact Suppose that we set ɛ to zero, so that after the collision, v + N was zero. Then the particle would be resting on the plane. In this case, we will have to apply a force to stop the particle fro being pushed through the plane. Suppose that the net force acting on the particle is F ext. The force F ext would include gravity forces, drag fro velocity, and any inter-particle forces such as springs. We need to stop the particle 4
fro accelerating opposite ˆn. To do this, we add a contact force F c that acts on the particle. Again, lets start with the frictionless case, where F c acts in the ˆn direction. So we can write F c = f c ˆn for soe scalar f c. To constrain the particle s acceleration, we can write ˆn ẍ(t) = 0 (2) which prevents the particle fro accelerating in the ˆn direction. The total force on the particle is F ext + F c,so ẍ(t)= F ext + F c Substituting into equation (2) yields = F ext + f c ˆn. so that ˆn Fext + f c ˆn = ˆn F ext + f c = 0 f c = ˆn F ext. (3) Now, if F ext is opposite ˆn, then f c is positive. That is, we require an outwards force to prevent the particle fro being pushed opposite ˆn. However, if F ext was along ˆn, lifting the particle off the plane in the positive ˆn direction, f c would have to be negative to stop the particle fro leaving the surface. If you want your planes to be sticky, you solve for f c using equation (3), and use whatever answer you get. But if you want the particle to release fro the surface, you will want to set f c to zero if equation (3) yields a negative value of f c. Finally, if you want to add friction, its about the sae as before (using a siplified odel of friction that is). If the particle is sliding along the plane, you add in a tangential force that is directly opposite to the velocity, with a agnitude of µ f c. (However, if the particle has no sliding velocity, things are a bit trickier. In this case, what you want to do is to copute a tangential force such that the coponent of ẍ(t) in the plane is zero. The strength of that force should not exceed µ f c ;ifit does, you should chop the agnitude down to be µ f c. Clear?) 3.3 Collision Detection In general, coputing exactly when a particle collides with a plane is difficult. Here we ll explain the right way to ipleent collision detection, though the displaceent ethod will do for this course. Again, iagine a particle dropping towards the floor. Suppose we consider the particle at ties t 0, t 0 + t, t 0 + 2 t etc. and suppose the tie of collision, t c, at which the particle actually strikes the floor, lies between t 0 and t 0 + t. Ideally, we d like to run our siulator up to tie t c, change the velocity of the particle (to ake it bounce off the floor), and then restart the siulator. If you re using an ODE ethod other than Euler s ethod, this is essential because the ODE solver doesn t realize that the otion equations are discontinuous at t c. (Yes, discontinuous the particle s position is continuous over tie, but its velocity is not at t c, and the velocity is a variable of the ODE.) 5
t 0 t c t 0 + t (interpenetration detected) Figure 2: At tie t 0 + t, the particle is found to lie below the floor. Thus, the actual tie of collision t c lies between the tie of the last known legal position, t 0,andt 0 + t. So in ters of ODE solution, we view this as solving up to tie t c, and then restarting at tie t c with a new initial velocity. The big proble of course is finding t c. At tie t 0, we find that the particle lies above the floor, but at the next tie step, t 0 + t, we find the particle is beneath the floor, which eans that interpenetration has occurred. If we re going to stop and restart the siulator at tie t c, we ll need to copute t c. All we know so far is that t c lies between t 0 and t 0 + t. In general, solving for t c exactly is difficult, so we solve for t c nuerically, to within a certain tolerance. A siple way of deterining t c is to use a nuerical ethod called bisection. If at tie t 0 + t we detect inter-penetration, we infor the ODE solver that we wish to restart back at tie t 0, and siulate forward to tie t 0 + t/2. If the siulator reaches t 0 + t/2 without encountering inter-penetration, we know the collision tie t c lies between t 0 + t/2andt 0 + t.otherwise,t c is less than t 0 + t/2, and we try to siulate fro t 0 to t 0 + t/4. Eventually, the tie of collision t c is coputed to within soe suitable nuerical tolerance. The accuracy with which t c is found depends on the collision detection routines. The collision detection routines have soe paraeter ɛ. We decide that our coputation of t c is good enough when the particle inter-penetrates the floor by no ore than ɛ, and is less than ɛ above the floor. At this point we declare that the particle is in contact with the floor (figure 3). How to actually ipleent all of this depends on how you interact with your ODE routines. One ight use exception handling code to signal the ODE of various events (collisions, interpenetration), or pass soe sort of essages to the ODE solver. 6
t 0 ε ε t c found (within tolerance) t 0 + t (interpenetration detected) Figure 3: When the particle is found to be within soe tolerance ɛ of contacting the floor, then t c is considered to have been coputed to within sufficient accuracy. 7