Contact constraint derivation question

Please don't post Bullet support questions here, use the above forums instead.
Post Reply
Himura78
Posts: 11
Joined: Sun Apr 23, 2017 12:32 pm

Contact constraint derivation question

Post by Himura78 »

Hi,
This question is not specifically about Bullet, but it's related to the derivation of the contact constraint used in Box2D. I apologise if this is not the correct forum for this question, but it didn't seem to attract any attention on the Box2D forum, so I thought someone here might be able to answer.

From Erin Catto's paper "Iterative Dynamics With Temporal Coherence" he states that when we calculate Cdot for the contact (normal) constraint, we use the product rule and get two terms, one which is essentially the velocity dotted with the normal, and the other which is the penetration dotted with the derivative of the normal. His paper goes on to say that the second term can be neglected when we make the assumption that the penetration is small. What I'm wondering is, why is this a valid assumption? Particularly when (as in the paper) discrete collision detection is being used, doesn't that mean that the penetration can be arbitrarily deep, depending on the velocities and sizes of the interacting bodies?
The other question I have is, since Cdot is always going to be linear in the velocity (and will be equal to JV) doesn't that mean that we should still be able to rearrange the equation for Cdot into JV, with both of these terms (ie without neglecting the second term)? Would it not be more accurate to do so?
Thanks :)
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Contact constraint derivation question

Post by Dirk Gregorius »

A non-penetration constraint for two bodies usually looks like this:

C = (p2 - p1) * n

The time derivative yields:

dC/dt = ( v2 + cross( omega2, r2 ) - v1 - cross( omega1, r1 ) ) * n + ( p2 - p1 ) * dn/dt

Here p1 and p2 are the contact points in global space on each body. r1 and r2 are the offset vectors from these points to the center of mass. The way we usually create contact points p2 and p1 are actually coincident. So the second term can be neglected because it is actually zero. Which means it is not small, but exactly zero. Even if the contact points are on the surfaces of each body and not coincident the second term will become zero. If you do the math you will get something like cross( p2 - p1, n ) which is zero as well since the normal and difference of the witness points (p2 - p1) are parallel. And as we remember from high school the cross product between two parallel (or anti-parallel) vectors is zero.

Regarding you second question for constrained rigid body dynamics we usually solve:

dx/dt = v
dv/dt = M * ( f_ext + fc ) = M * ( f_ext + JT * lambda )
C = 0

Three equations with three unknowns. Sadly the equations cannot be solved this way. So people usually utilize the fact that there are two more (hidden) constraints. The velocity and acceleration conditions. E.g. if you constraint a particle to move on a circular path obviously there cannot be any velocity or acceleration away from the arc (momentarily). Otherwise we move off. The point here is that is all three conditions must be satisfied. If you only satisfy e.g. the acceleration and velocity conditions you didn't solve the original problem. Finally, the velocity and similarly the acceleration constraint have a special form:

dC/dt = del_C/del_x * dx/dt + del_C / del_t = J * v + del_C / del_t

So yes, the velocity constraints are indeed linear, but note the original problem is not! So if you only solve on the velocity level you solve a linearization of the original problem which usually results in constraint drift. The constraint drift can then be handled with some kind of Baumgart'ish stabilization or orthogonal projection of the position constraints.

The second term in this equation del_C / del_t is usually zero in rigid body dynamics because the constraints don't explicitly depend on time. An example where you need the second term could be a boat on a moving water surface.

HTH,
-Dirk
Himura78
Posts: 11
Joined: Sun Apr 23, 2017 12:32 pm

Re: Contact constraint derivation question

Post by Himura78 »

Thanks for your reply Dirk, that makes more sense now.
Post Reply