Question about kNormal computation in box2d-lite

Started by
2 comments, last by OferKapota 3 years, 3 months ago

Hello, in box2d-lite, in the PreStep function, the kNormal value is computed for the impulse magnitude.

What i don't understand, is where the term:

(Dot(r1, r1) - rn1*rn1)

Coming from? Is it an implementation of the term:

Dot(r1perp, n)^2

As in Chris Hecker's column on 2d collision response?

Thanks

Advertisement

Code of box2d lite

float rn1 = Dot(r1, c->normal);

float rn2 = Dot(r2, c->normal);

float kNormal = body1->invMass + body2->invMass;
kNormal += body1->invI * (Dot(r1, r1) - rn1 * rn1) + body2->invI * (Dot(r2, r2) - rn2 * rn2);
c->massNormal = 1.0f / kNormal;

C^2 = A^2 + B^2 // Teorema de pitagoras

C^2 = Dot(r1,r1)

A^2 = rn1 * rn1

B^2 = C^2 - A^2

//another way to formulate it


float rcn1 = Cross(r1, c->normal);

float rcn2 = Cross(r2, c->normal);
float kNormal = body1->invMass + body2->invMass;
kNormal += body1->invI * rcn1 * rcn1 + body2->invI * rcn2 * rcn2;
c->massNormal = 1.0f / kNormal;

B^2 = rnc1 * rnc1

And there are still more ways to formulate the same

Thanks a lot Gustavo! Ok, i see now where I got confused previously, and now I understand why this is correct.

Thanks!

This topic is closed to new replies.

Advertisement