Constraint Formulation

I'm trying to understand the formulation of a number of the constraints used to model joints. I went through the slides and was successful in understanding the distance constraint. However, when modeling the spring-damper and point-to-point constraints I'm having problems.

I think my problem is, for the spring-damper constraint, that I don't know what position constraint equation I need to perform the derivative on. The code comments only have "magic formulas." I understand that some of the equations are used to obtain the various constants needed in the spring-damper dynamics equations (spring constant, damping coefficient, natural frequency). More specifically, I don't understand where the gamma and bias computations come from.

Secondly, the formulation of the point-to-point constraint used to model a revolute joint (excluding motors). I think I understand correctly in that the position constraint is Pa = Pb, therefore Pa - Pb = 0. When I expand this out and perform the derivative I obtain Va + Ra x Wa - Vb - Rb x Wb = 0 (which makes sense since the relative velocity should be zero). In the slides you say to solve for V. Is this the correct velocity constraint? If so, how do I go about solving this since there are two velocity variables? Am I missing an equation? Is this why you use a mass matrix for this constraint? How did you formulate the mass matrix?

Thanks in advance for the help,

William
The distance constraint in Box2D has some extra tech to model a spring-damper. You can read about the idea here:
http://ode.org/ode-latest-userguide.html#sec_3_8_0

For any constraint you want to solve for the constraint force (or impulse). You then apply the impulse to update the velocities of the connected bodies.

For the revolute joint, I recommend looking at Box2D_Lite, found here:
http://code.google.com/p/box2d/downloads/list
Ok, the link to ODE ill have to stew on for a while. I see that they talk about why its used and how it helps, but how did they arrive at doing that way...

I have downloaded the Lite version and I'm not sure what I'm looking for in it that is different than the full version besides ignoring the motor code. Is there some documentation im missing in there that explains how the point-to-point constraint is derived?

Thanks and sorry for being dense
Which presentation are you looking at? Which pages are you having trouble with? Did you try to solve for the constraint force?

You have already derived the velocity constraint. The next step is to isolate the velocities and identify the Jacobian. Next you setup a linear momentum equation involving the mass, velocity delta, and constraint impulses. You can solve the linear momentum equation for the new velocity in terms of the old velocity and the constraint impulse. Substitute this expression into the velocity constraint and solve for the constraint impulse. Once you have the constraint impulse, you can compute the velocity update using the linear momentum equation.
I'm looking at the 2008 GDC presentation, slide 28, "A Recipe for J."

1. Use geometry to write C: C = Pa - Pb = 0
2. Differentiate C wrt time: dC/dt = Va + Wa x Ra - Vb - Wb x Rb = 0
3. Isolate v

Isolating v is where I get confused. There are two velocity variables. What am I missing here?

I think I understand the rest of the solution:
P = M * Vdelta = M * (v2 - v1)
v2 = v1 + P * Minv
va1 + P * Minva + Wa x Ra - vb1 - P * Minvb - Wb x Rb = 0
P * (Minva - Minvb) = Vb1 + Wb x Rb - Va1 - Wa x Ra
P = inv(Minva - Minvb) * (Vb1 + Wb x Rb - Va1 - Wa x Ra)
Then apply to the bodies.
In this case v is a vector of all velocities stacked in column form.
Code:
v = [vA]
     [wA]
     [vB]
     [wB]


So write Cdot as J * v to find J. You will have to use the trick where the cross product is equivalent to multiplication by a skew-symmetric matrix.
Ah yes, thats exactly what I was missing. I was able to finish the derivation from there. Thanks a lot!
I have another question regarding the Weld joint in the latest release. I understand that its basically a point to point constraint plus and angle constraint. The Jacobian being:

| -1 -skew(Ra) 1 skew(Rb) |
| 0 -1 0 1 |

where 1 is a 3x3 identity matrix and 0 is a 3x3 zero matrix.

When I attempt to compute K I'm left with a 2x2 block matrix. In the source it seems that matlab was used to reduce K to a 3x3. How did it get from the 2x2 block matrix to a 3x3 matrix?

It makes sense that the result is a 3x3 because in 2D there are only 3 DOF and we are removing all of them.
Here's my comments in the code:
Code:
   // J = [-I -r1_skew I r2_skew]
   //     [ 0       -1 0       1]
   // r_skew = [-ry; rx]

   // Matlab
   // K = [ mA+r1y^2*iA+mB+r2y^2*iB,  -r1y*iA*r1x-r2y*iB*r2x,          -r1y*iA-r2y*iB]
   //     [  -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB,           r1x*iA+r2x*iB]
   //     [          -r1y*iA-r2y*iB,           r1x*iA+r2x*iB,                   iA+iB]


We have to be careful to derive the skew matrix correctly in 2D.

The skew matrix has the property:

skew(y) * x = cross(y, x)

Here we want cross(omega, r). omega is the angular velocity (a scalar), and r is the radius vector (2-vector). The result of the cross product should be a 2-vector in the plane.

cross(omega, r) = [-r.x * omega; r.y * omega] = [-r.x; r.y] * omega = -skew(r) * omega

So skew(r) = [r.x; -r.y] (a 2-vector)

Everything else follows from this.
Ok, I think I see now. When I derived the revolute joint I obtained K in 3D then saw that it could reduce in 2D since all the z components are zero and eventually obtained the same result.

Instead what I should have done was use the 2D skew matrix instead of the 3D. Thanks, I think I can take it from here!

Original thread: https://box2d.org/forum/viewtopic.php?t=4996