Bullet Pt2Pt Constraint and Jacobian entry

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

Bullet Pt2Pt Constraint and Jacobian entry

Post by Dirk Gregorius »

I looked at the Point2PointConstraint class and have a question how the constraint is satisfied ( Point2PointConstraint::SolveConstraint( dt ) ). For my understanding two steps have to be taken:

1.) First calculate the constraint error
This is very obvious here. Simply calculate the relative drift and relative velocity at the pivot point.

2.) Find correction (impulse) such that constraint error is repaired
Here I can't follow anymore.

Questions:

(1)
The Jacobian for the Pt2Pt constraint is a 3 x 12 matrix and it has the following entries:

J = ( I -R1 -I R2 )

I := Identity matrix (3x3)
R1 := Cross matrix for offset vector from CM body1 to pivot point in world space (3x3)
R2 := Cross matrix for offset vector from CM body2 to pivot point in world space (3x3)

How does this relate to the JacobianEntry class and what is the "normal" entry in this class?

(2)
We need to find an impulse such that constraint error is resolved. How is this achieved using the JacobianEntry class? Derivation? I have solved this problem by finding an impulse such that relative velocity at the pivot point is resolved, but I don't take the Jacobian into account. So how can use the Jacobian to find the repairing impulse?

(3)
For a hinge joint the resulting impulse would be a 5 x1 vector. How do I build a linear and angular impulse from this data?

A sketch of the basic idea would be very helpful - especially the role of the Jacobian!

Regards,

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

RE:

Post by Dirk Gregorius »

I thought about the problem and came up with the following idea:

The velocity update for the two bodies is:

M * du /dt = f_ext + JT * lambda

Here u is the generalized velocity vector for body1 and body2, JT is the transposed jacobian and lambda is a vector of langrange multipliers.

Since we use linear dynamics we can use superposition and apply the external and constraint forces subsequently. So the velocity update because of the the constraint forces becomes:

M * du /dt = JT * lambda

The compatibility equation (velocity constraint) for the two bodies is:

J * u(t) = 0

Numerical integration of the Newton-Euler equation:

M * ( u(t+dt) - u(t) ) / dt = JT * lambda

<=> u(t+dt) = u(t) + M^-1*JT*lambda*dt

Semi-implicit integration, therefore

J * u(t+dt) = 0

Plug integrated Euler-Newton into compatibility equation:

J * [ u(t) + M^-1*JT*lambda*dt ] = 0
<=> J*M^-1*JT * lambda * dt + J*v(t) = 0

This is a linear system: A * x + b = 0

If we look now sharply we see that J*v(t) is the constraint error and lambda * dt is the wanted impulse. We define

A := J*M^-1*JT
x := lambda * dt
b := J*v(t)

=> lambda = A^-1 * constraint error (J*v(t))

So the wanted linear and angular impulses for body1 and body2 are simply:

P = JT * lambda

Is this correct?

-Dirk
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

I renamed some variables to make the source a bit more clear.
Basically the JacobianEntry calculates and stores some values to perform constraint correction:

for two rigidbodies, A and B it precomputes

angular Jacobian entries J for both bodies
Minv Jt for both bodies
Adiag, the diagonal entry in the system matrix A = J Minv Jt

This information can be used in a Gauss-Siedel iterative LCP solver, or to correct the constraint error on a per-body pair.

Once I got some time I will add some more details, see the renamed variables in JacobianEntry here:
http://www.erwincoumans.com/Bullet/Bull ... tated.html