Resting Contact in rigid body simulation. . .

Please don't post Bullet support questions here, use the above forums instead.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Resting Contact in rigid body simulation. . .

Post by Dirk Gregorius »

For 2-body constraints you only have one J ( actualy you have two, but J1 = -J2 )
Actually this is not correct in the general case and this is in my experience the reason people ususally have problems with prismatic joints. The linear constraints for a prismatic joint are:

C1 = (x2 - r2 - x1- r1) * u1
C2 = (x2 - r2 - x1- r1) * v1

Here u1 and v1 are mutually orthonormal axes to the slider axis. Now we build the time derivative and find the Jacobian by inspection (here I use C1):

dC1/dt = d/dt * (x2 - r2 - x1- r1) * u1 + (x2 - r2 - x1- r1) * du1/dt

The point is that the time-derivative of u1 doesn't vanish as it does for non-penetration constraints, so we get:

dC1/dt = (v2 - w2 x r2 - v1- w1 x r1) * u1 + (x2 - r2 - x1- r1) * (w1 x u1)

In this case the angular entries of J1 and J2 don't match anymore. Actually they also don't match for a simple spherical joint since r1 != r2 usually.


Cheers,
-Dirk
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Resting Contact in rigid body simulation. . .

Post by Dirk Gregorius »

I assume you were talking about particles, right? Then this is indeed correct and actually J1 + J2 + ... + Jn = 0 must hold if I remember correctly.
Erin Catto
Posts: 316
Joined: Fri Jul 01, 2005 5:29 am
Location: Irvine
Contact:

Re: Resting Contact in rigid body simulation. . .

Post by Erin Catto »

We talked about prismatic joints a while back. Michael hinted at an important principle: when you apply an impulse to satisfy a pair-wise translation constraint, you should apply an equal and opposite impulse on both body at the same point in space. This is necessary to conserve the momentum of the two body system.

For a linear constraint you can place the impulse at any point along a line and produce the same linear and angular impulse on each body, so the Jacobian is not unique.

I use a prismatic constraint as Dirk specified, yet the impulse generated is still equivalent to an equal and opposite linear impulse applied at a single point in space.

I still prefer to generate Jacobians via differentiation, but the geometric view is also important for understanding.

Edit: I realized that even if you can slide the impulse point along a line, it may not be possible to make J1 == -J2.
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Resting Contact in rigid body simulation. . .

Post by bone »

John Schultz wrote:The constraints are solved pair-wise between two bodies, with no limit to the number of pairs.
There may be some confusion - I'm perfectly aware of your statement. I'm talking about constraints between three or more bodies. Maintaining the area of a triangle in a particle system such as cloth can be done with a 3-body constraint. Likewise with the volume of a tetrahedron with a 4-body constraint.
If you add a displace-position-and-track energy step, SI can allow for relatively stiff solutions without iterating (for example single-pass @ 100Hz with no per-frame iteration).
I'll get to that at some later point. I've looked over your website before and haven't completely understood everything you are doing (yet). I am interested in understanding it, just not at this moment.
Re: external storage- I store and track contacts (helpful for holding dynamic constraints such as static friction), though certainly much simpler than populating matrices.
My term 'external storage' wasn't particularly accurate, sorry. Yes you'll have some sort of storage for constraints (of which we usually consider contacts as a version of, even if they're only temporary constraints). I'm only talking about the matrix solver results (and even the calculated inputs, possibly).
mewert
Posts: 52
Joined: Sat Oct 08, 2005 1:16 am
Location: Itinerant

Re: Resting Contact in rigid body simulation. . .

Post by mewert »

Yes, my mistake. J1 != J2. I have my Jacobians split into a linear and angular contribution. For my linear contribution J1x = -J2x, but I have different J1w and J2w angular. I went over that quickly to get to my main point.

Anyways, the point of my post remains the same. You can extend the system to 3 or more bodies fairly easily by adding more per-body jacobians to the constraint. Converges really well because it is solving the GS iterative solution properly ( not skipping any entries in the matrix ).

For the 3-particle triangle-area constraint this would work fine, of course you are linearizing quite a non-linear effect, so your results may vary.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Resting Contact in rigid body simulation. . .

Post by Dirk Gregorius »

For the 3-particle triangle-area constraint this would work fine, of course you are linearizing quite a non-linear effect, so your results may vary.
The velocity constraints are linear, right? Basically it is J * v = 0 which is a linear system. The position constraints on the other side are non-linear, this is why they are harder to solve, hence NGS vs GS for example. From my experience you can catch the non-linear effects with more Newton iterations (actually as in the cloth paper we discussed lately). Baumgarte stabilization basically linearizes the position constraint, so it suffers from problem with high angular velocities.

I have a question though. While J * v = 0 is linear at a discrete instance in time, the Jacobian itself is a matrix which elements are functions of the time. I assume that these functions are indeed non-linear. What about this effect? This reminds me a little at calculus of variations where the variables x are actually (vector) functions of some value (usually time), e.g. x(t). Are those things related?

Cheers,
-Dirk
mewert
Posts: 52
Joined: Sat Oct 08, 2005 1:16 am
Location: Itinerant

Re: Resting Contact in rigid body simulation. . .

Post by mewert »

The velocity constraints are linear, right?
Only if your timestep is 1/infinity :)

For a sphere penetrating an immovable flat plane, or a point-to-point constraint on one particle achored to an immovable body; if we have an initial velocity of zero; our linear system is an exact model of the physical system.

The velocity constraints are pretty striaghtforwards.
You can mess around and get better approximations for your position error though.

Let's take angular error as an example: rather than using the fact that sin(x) ~= x when x is small.. You can actually use arcsin(x) to calculate your error. I'm probably using the wrong trig function here, I'm digging up a memory of something I did long ago so please don't divert this thread by correcting me ;) You probably wont use the inverse trig function though, for performance reasons. But if your game involves constantly spinning rag-dolls at low frame-rates ( "Spinning merry-go-round in a pit of alligators: The game." ) maybe you will need it. I see this as another example of thinking geometrically helping you. I look at the positional error as what velocity target I need to correct that constraints error in one time-step. Actually I don't know what the calculus pops out at the end. It's a dot product, I think, which ecapsulates the approximiation sin(x) ~= x.

For the triangle area we are talking about x^2. But when x is small x^2 ~= x, so maybe its not so bad.
This reminds me a little at calculus of variations where the variables x are actually (vector) functions of some value (usually time), e.g. x(t). Are those things related?
Yup. It's like fitting a smooth curve using a piecewise linear curve. In the limiting case you have a perfect fit.
Erin Catto
Posts: 316
Joined: Fri Jul 01, 2005 5:29 am
Location: Irvine
Contact:

Re: Resting Contact in rigid body simulation. . .

Post by Erin Catto »

I think Dirk means that velocity constraints are linear because you can solve velocity constraints at an instant of time by solving a linear equation (or LCP). On the other hand, even with time frozen, you generally have to solve a nonlinear equation to satisfy position constraints.

Geometrically speaking, velocity constraints serve to ensure the system moves tangentially to the constraint manifold. At a given point on the manifold, the tangent space is linear. Tangent constraints are enough to keep the velocities under control, but can lead to overshoot of the constraint manifold so that position errors develop.
mewert
Posts: 52
Joined: Sat Oct 08, 2005 1:16 am
Location: Itinerant

Re: Resting Contact in rigid body simulation. . .

Post by mewert »

Yup, I understand that, that's why I said it was accurrate in the limiting case where t -> 0. ( 1/infinity )
Post Reply