# Problem with impulses in my physics engine

I'm currently developing a small 3D impulse-based physic engine for a CS project. It uses GJK for collision detection and is kind of stable at the moment. Nevertheless, I'm not satisfied with my collision response as rigid bodies appear to gain more and more momentum with each bounce, although only under some configurations.

I use Newton’s Law of Restitution (pictured immediately below) for instantaneous collisions with no friction. I checked this formula again and again, and I also checked if the magnitude of the contact normal is 1, and all seems fine. The direction of the bounce and the induced rotation are convincing but the impulse is just sometimes too strong.

I think my problem may lie within the impulse application part; in my mind, the impulse is the force necessary to separate two touching points of two bodies plus a certain magnitude depending on the coefficient of restitution (0.7 in my tests). I compute an impulse for each detected contact point and apply it at the contact position.

For example if a cube falls right to the floor, there will be 4 impulses, each one at a vertex of the bottom face of the cube. For each of the four contacts, I do something like this:

J = computeImpulse(contact)
A.applyImpulse(J, contact.pos)
B.applyImpulse(-J, contact.pos)


I'm a bit confused. Is this the correct approach, or should I apply half of the impulse to each body? Or, should I rather apply a fraction of the impulse depending of the mass of the bodies? Or, is the problem just somewhere else (e.g., in the formula)?

I don't know if someone has an easy answer for me, as it's a rather specific problem, but thank you for your help. :)

• Damn, I am so glad for my previous mechanics exam I only had to know that resitution = speed of separation/speed of approach :) – The Communist Duck Jun 18 '11 at 14:21
• If something is incrementing or compounding unexpectedly, it could be related to a variable not being localized properly (e.g., its scope is a bit too global and it's not being reset at the right place in your code). It may be beneficial to check into this type of cause to at least rule this out. – Randolf Richardson Jun 18 '11 at 14:29

As you already suggested, you have to take the mass of the objects into account to calculate the change of velocity caused by the impulse. Namely, divide the impulse by the mass for each object.

You can find this and much more information in this paper "Impulse-based Dynamic Simulation of Rigid Body Systems" from Brian Vincent Mirtich.

Page 60 shows it in detail:

p       -> impulse
delta_v -> change of velocity caused by the impulse
m       -> mass

p(t)       = m * delta_v(t)
so:  delta_v(t) = p(t) / m


Here is another paper about it called "A Real-time Capable Impulse-based Collision Response Algorithm for Rigid Body Dynamics" from Florian Schornbaum. You can find that calculation at Page 23.