Problem with rotation for the normal constraint in 2D

(probably a question for Erin Catto)

I've looked around on the board to try to find the answer to this, as it has to do with the 2D cross product, but I can't find quite what I'm looking for.

Let me first say I'm implementing the white paper Iterative Dynamics with Temporal Coherence in my own framework, outside of Box2D, but still in 2D (and in C++).

When I make the Jacobian for a body with the ground (right now, all bodies are just squares of equal mass), I follow the white paper's convention that Jmap(i,0) for that constraint i is the ground (in this case, -1 instead of 0) (formed similarly for two interacting bodies, with the normal going the right way and what have you). Instead of 6-vectors for the Jacobians, I use 3-vectors, two spots for x and y, and one for rotation. The first two components of that Jacobian are the normalized x and y of the normal of the ground, and the rotation component is what I'm really iffy on. I represent rotation completely as a single scalar, and the white paper assumes 3D for the cross products and getting a vector to rotate around. I thought that taking the arc-sine of the "cross product" of the two vectors would work (for r cross n, it would be r.x*n.y - n.x-r.y) for the normalized vectors.

Help?
The third part of your Jacobian need not have units of an angle. Imagine multiplying the Jacobian with linear and angular velocity:

Code:
dot(J, v) = dot([Jx Jy Jangle] * [vx vy omegaz])
   = Jx * vx + Jy * vy + Jangle * omegaz


Typically Jx and Jy are dimensionless, so J*v has units of length over time (meters per second). Since omegaz has units of one over time, Jangle must have units of length.

I recommend reading my later presentations to get a simpler explanation. You can get them here: http://code.google.com/p/box2d/downloads/list
So does this mean I just leave out the arcsine, and put in that "cross product" as the third component? I've since tried to add in friction, and nothing I do can seem to get it to work right. I don't know if I'm missing something or have something somewhere I shouldn't so... here's a short summary.

Everything is uniform mass, equal size squares to start off with.
Mass : 10
Side length : 20
Inertia : Mass * Side_length * Side_length / 6
(should the squared value be half this?)

Integrate applied forces:
- Add to each object's velocity the gravity vector (0,-G) * delta_t / mass

Generate contacts:
- if an object is colliding with world geometry, make the normal and friction constraints between the box and it
- if two bodies are colliding, generate normal and friction contacts
- Since its 2D, "B" is the corresponding J with the x and y divided by mass and the last component divided by inertia

Generating normal constraint:
- use normalized vectors of contact normal and r (from center of mass to contact point)
- J.x and J.y are n.x and n.y, J.y is (possibly arcsine?) of the "cross product" r x n
- lambda is unbounded on the normal constraint

Generating friction constraint:
- use "u" as the parallel velocity to the contact (relative velocity "v" - (v dot n) * n)
- J.x and J.y are u.x and u.y, J.z same as for the normal constraint but with r crossed with u instead of n
- lambda is bounded from 0 to mu * mass * g

Solve contacts:
- as outlined in Algorithm 4 in Iterative Dynamics with Temporal Coherence

Apply constraint forces:
- using the work variable a from Algorithm 4 above (where a is an array of 3-vectors for each body), add to the velocity (a.x,a.y) * delta_t, and add to the angular velocity a.z * delta_t / inertia
(I get the same results if I use the outline Algorithm 2 for computing Fc = Jt * lambda)

Update positions:
- position += velocity * delta_t
- theta += omega * delta_t

Is there anything that looks wrong at a glance?

(By the way, I just have to say, it's really, really cool having the author of the white paper you're trying to implement personally getting on a forum and helping people out with it.)
Most of what you have there looks good. I recommend reading some of the other presentations here: http://code.google.com/p/box2d/downloads/list

Box2D_Lite provides a great framework for learning about this stuff.

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