Hello, everyone!
I'm currently struggling with a little problem. I have multiple bodies and I want to calculate their common angular velocity about their center of mass. I have no problem calculating the center of mass. Then I calculate individual angular moments about the center of mass and add them together. Then I divide the whole thing by the sum of inertias. It looks like this:
There must be something wrong with this, because it gives slightly different values depending on the bodies' angular orientation.
Thanks for your help.
I'm currently struggling with a little problem. I have multiple bodies and I want to calculate their common angular velocity about their center of mass. I have no problem calculating the center of mass. Then I calculate individual angular moments about the center of mass and add them together. Then I divide the whole thing by the sum of inertias. It looks like this:
Code:
totalInertia = 0;
totalAngMomentum = 0;
for (body: bodies) {
distance = dst(body.getPosition(), centerOfMass);
inertia = body.getInertia() + body.getMass() * distance^2;
ang_vel = body.getLinearVelocity().dot(normalize(body.getPosition() - centerOfMass).rotate(PI/2)) / distance;
totalInertia += inertia;
totalAngMomentum += inertia * ang_vel;
}
angVelocity = totalAngMomentum / totalInertia;
totalAngMomentum = 0;
for (body: bodies) {
distance = dst(body.getPosition(), centerOfMass);
inertia = body.getInertia() + body.getMass() * distance^2;
ang_vel = body.getLinearVelocity().dot(normalize(body.getPosition() - centerOfMass).rotate(PI/2)) / distance;
totalInertia += inertia;
totalAngMomentum += inertia * ang_vel;
}
angVelocity = totalAngMomentum / totalInertia;
There must be something wrong with this, because it gives slightly different values depending on the bodies' angular orientation.
Thanks for your help.