# Impulse based physics: Derivation of Impulse

This topic is 4104 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've finally managed to get my first interactive rigid body simulation to work properly. Avi Not entirely sure if the result is correct though (I could only compare it with 3ds max reactor(havok), but it doesn't have ellipsoidal bounding volume). Do you think the result is acceptable (realistic enough)? Chris Hackers articles were more than helpful, although I don't understand the impulse derivation entirely. I've also referred to the book "Physics for Game Developers" For rigid bodies that cannot rotate, the relative velocity (for center of masses) after impact is proportional to the relative velocity before impact. This is justifiable as no angular effects are considered and total system momentum is dependent only on linear velocities. So the total momentum is conserved. However with angular effects, the impulse derivation uses the same principle of keeping the relative velocities before and after impact proportional, but this time the velocities at the point of contact are considered. How will such an impulse conserve total angular momentum? Am I missing something here? Thanks for your help.

##### Share on other sites
What impulse are you refering to? The general solution goes as follows:

1) You integrate the system forward in time without considering the constraints
2) Now you seek impulses P such that post-velocities v' satisfy the velocity constraints. Note that P or v are vector quantities containing all velocities of the rigid bodies, e.g. v = ( v1, w1, ..., vn, wn ) where v is the linear and w the angular velocity vector. In terms of the formulation this is relatively simple:

a) Apply an impulse P...
v' = v + M^1 * P

b) ...such that the post-velocities satisfy the velociyt constraints...
J * v' = 0

c) ... also knowing the direction of the impulse...
P = Transpose( J ) * lambda

J is the Jacobian matrix of the constraints and lambda are the Lagrange multipliers. The Jacobian is found through derivation of position constraint. If you look at Shabana or Erin Catto's slides the ususal way goes like this:

C(p1, R1, p2, R2) = 0
dC/dt = del_C/del_x * dx/dt + del_C/del_t

here del means the partial derivative. The formula above is the total differential of the constraint equation. This looks awful, but in practise this is quite easy. Take for example the distance constraint between two particles:

C(p1, p2) = |p2 - p1| - L0 = 0

dC/dt = (p2 - p1)/|p2 - p1| * (v2 - v1) = u * v2 - u * v1 = ( -u u ) * Transpose( v1 v2 ) and u being defined as u = (p2 - p1)/|p2 - p1|

So in order to compute the impulses you usually do the following:

1) Write down the position constraint
2) Build the time derivative and find the Jacobian by inspection.
3) Using the formulas from above your impulse is J * M^-1 * Transpose( J ) * lambda = - J * v
4) P = Transpose( J ) * lamba

As an execrise you can take the non-penetration constraint you were actually asking about I belive:

C(p1, R1, p2, R2) = ( (p2 + r2) - (p1 + r1) ) * n where n is the contact normal and r point from the COM to the contact point. You should be able to define the Jacobian and the collision "matrix" (actually a scalar here) which is identical to all the formulas you find in the references (e.g. Baraffs Siggraph lectures)

HTH,
-Dirk

##### Share on other sites
I was referring to the impluse derived in Chris Hecker's article
http://chrishecker.com/images/e/e7/Gdmphys3.pdf

Thanks for the explanation, but I couldn't get much of it. Guess my mathematics is not up to that level yet. Can you please suggest some reading material that I could study?

The method you describe seems to be able to handle multiple simultaneous contacts, something that Hecker's articles don't describe. This certainly is the next exercise. Could you kindly suggest some resources (Books, papers ..)

Thanks

Chandan

##### Share on other sites
I gave recommendations in these links, both material and how to study it:

http://www.gamedev.net/community/forums/topic.asp?topic_id=462905&whichpage=1�
http://www.gamedev.net/community/forums/topic.asp?topic_id=456919&whichpage=1�

The most valueable resource in my opinion is Box2D and its associated slides from Erin Catto. See www.gphysics.com - I really learned very much from understanding the Box2D code and porting it to 3D and reading the presentations. Just give yourself some time to learn the stuff and don't be to impatient. From the video I saw you already did a good job :-)

If you have questions you might consider posting them on the Bullet forum!

##### Share on other sites
Thank you Dirk. Will look at all the material you have recommended.

##### Share on other sites
What Dirk is talking about is a little different from the impulse based methods. The math behind it is rather complex comparatively, too. It's the ultimate proper way to simulate physics, but it's considerably slower than impulse based methods because you have to invert a matrix. That's O(n^3) where n is the number of constraints.

Compared with O(nlogn) (sometimes called O(n) in practice, since the growth is so slow) for impulse based engines, it's just not practical for large systems, so impulse based methods have their place.

Quote:
 Original post by chand81However with angular effects, the impulse derivation uses the same principle of keeping the relative velocities before and after impact proportional, but this time the velocities at the point of contact are considered.How will such an impulse conserve total angular momentum? Am I missing something here?Thanks for your help.

Angular momentum and linear momentum are basically "orthogonal", they can be treated seperately. Hecker's method that doesn't take into account angular effects is still correct, just incomplete. That's important to understand. The equations for linear momentum aren't going to change when you add in angular effects, aside from effecting the (linear) collision velocities of the contact points.

When Hecker adds in angular effects, it's done in two places. First, angular velocity changes the (linear) velocity of every point on a body that's not the center of mass. This is through the familiar "velocity = radius cross angular velocity".

The two contact points can now be looked at in isolation. All that needs to happen to happen is that the points bounce off of each other and obey the coefficient of restitution with their final speeds. Just like with a strictly linear collision. We try to find the impulse (j) that accomplishes this.

As I stated before, the linear momentum works the same here as it did before. No extra terms or anything like that are added. The neat things comes from the knowledge of how to apply the collision impulse to the angular momentum of each body. The strictly linear collision code basically assumes that the bodies collide dead on, and so don't cause any spin. So this new method is the more general case.

If you remember that "torque = force cross radius", you should be able to see that the collision impulse could also produce torque on the body. The odd thing that throws alot of people is that wether the collision is dead center or barely glancing, the change in linear momentum is the same.

So the changes in angular momentum to each body are actually determined indirectly. The real goal is to control the collision points' velocities. Changes to angular momentum occur as a byproduct of the collision impulse happenining off-center.

I hope I answered your question. It wasn't a very formal explanation. If you really wanted to see how angular momentum is conserved mathematically, you could show that the collision impulse depends on the angular momentum of both bodies, and then feeds-back to the angular momentum of either body. But the math might get a little overwhelming unless you have access to something like Maple or Mathematica.

##### Share on other sites
Quote:
 What Dirk is talking about is a little different from the impulse based methods.

No, actually it is not :-). I just described a general solution how to compute arbitrary momemtum conserving impulses as a function of the constraint function. Whether you solve for all impulses with a direct method or if you compute sequential impulses, it doesn't matter. It all depends on the number of constraints you consider. If you just consider *one* non-penetration constraint the formula give you exactly the formula found in Baraff or other common papers. Of course you could try solve a full contact manifold with up to four points using e.g. Dantzig method...

##### Share on other sites
I don't how how much this will help, but there is a simple impulse based physics engine called box2d (2d only)

http://www.box2d.org/

cheers,
Paul

##### Share on other sites
Quote:
Original post by DonDickieD
Quote:
 What Dirk is talking about is a little different from the impulse based methods.

No, actually it is not :-).

Let me rephrase. Constraint minimization uses more complex mathematics (partial derivatives and matrix inversion) than a more naive pairwise collision response system. One requires fairly advanced mathematics to understand, while the other doesn't require more than high school algebra to implement.

They both do effectively the same thing. Using a Jacobian is the more "proper" method, but is computationally more expensive, and more difficult to wrap your mind around if you don't have the proper background.

That's all I meant. I thought your explanation was very good, but I could see how it would leave a hobbyist a little confused. I think it's better for most programmers to stick with a simpler pair-wise system until/unless they really want to get into heavy duty stuff. I didn't get that impression from the OP.

##### Share on other sites
Quote:
 Original post by Numsgilwether the collision is dead center or barely glancing, the change in linear momentum is the same.

I'm not sure I can agree on that statement.
Although the equation for change in linear velocity is the same even with angular effects considered, the equation for impulse J changes drastically. It now depends on the collision point. So for a dead center collision J will be large and for a barely glancing collision J will be very small unless there is friction (in which case the direction of J changes). And when J changes, so does the change in velocity/momentum.

My question still remains unanswered though: Is there a proof that the total angular momentum (or the total energy) is preserved if we have COR=1?
Or even better, can we derive J based on the principle of conservation of angular momentum?

P.S. I'm always on the lookout for study material - there is always college after school ;-)

Thanks.

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633734
• Total Posts
3013587
×