Advertisement

Rigid Body collision response

Started by August 17, 2012 10:45 PM
2 comments, last by Aressera 12 years, 6 months ago
I am writing a 2D physics engine right now. The dynamics and the collision detection works fine. And I can solve its velocity with impulse, no problem. My questions is: what is a good way to solve interpenetration? I looked up the Box2D slides that talked about sequential impulse, but I think it's assuming that the interpenetration is already resolved (or maybe I got it wrong, since I don't completely understand the whole idea of sequential impulse, if someone could explain, that would be nice). Chris Hecker's paper had nothing over interpenetration either. I know I can simply move both object half of the penetration away from each other, but what about rotation? And most of the time 2 objects that are colliding should have different mass and moment of Inertia, how do i account for that?
The sequential impulse method does not assume interpenetration to be solved. If you check the slides there are some equations with a parameter beta, which controls the speed in which interpenetration is solved. Impulses are applied such that the constraints are fulfilled. Where the constraints also include interpenetration constraints. The parameter beta adds some additional impulse to not only keep the bodies from penetrating further, but to move them apart.
Advertisement

The sequential impulse method does not assume interpenetration to be solved. If you check the slides there are some equations with a parameter beta, which controls the speed in which interpenetration is solved. Impulses are applied such that the constraints are fulfilled. Where the constraints also include interpenetration constraints. The parameter beta adds some additional impulse to not only keep the bodies from penetrating further, but to move them apart.


thanks, i've been wondering for a while now rather sequential impulse only solve for velocity or both velocity and interpenetration. I guess i will look over the slides again
Let me clarify a few things:

The vanilla sequential impulse method doesn't deal with interpenetration, though it is a natural outcome of discrete time step simulation (even with CCD, since that can't always detect all future penetrations).

In order to resolve penetrations and push intersecting objects away from each other you need to know the current penetration distance D. Most physics engines will use a velocity-based correction method ('bias' velocity). The difference between bias velocity and normal velocity is that bias velocity is only valid for a single frame, it gets reset to 0 after each simulation step. This keeps objects from continuing to move away from each other after they have separated.

The bias velocity is the accumulation of bias impulses computed in order to counteract any penetration, they behave and are computed exactly like regular normal-direction impulses except that they satisfy a different constraint. Most systems will compute the magnitude of the bias impulse for a particular 2-body pair to be enough to push them say 50% of the way apart in one timestep (not 100% because that can cause bouncy simulations).

So:
biasImpulse = 0.5*D*normalMass / timestep;

where normalMass is the combined inertia of the two bodies along the normal direction. The stability can be improved even more if you disregard penetrations smaller than a certain amount (say a few mm).

Thus, your integration loop will look something like this (with a symplectic Euler integrator):
[source lang="cpp"]Vec force = computeForces( object );
object.velocity += (force/object.mass)*timestep;
object.biasVelocity = 0;

findCollisions(); // Finds contact points, normals, and penetration distances.
solveCollisions() // This is where the sequential impulse constraints get solved.

object.position += (object.velocity + object.biasVelocity)*timestep;[/source]

This topic is closed to new replies.

Advertisement