## How to conserve angular momentum

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

### How to conserve angular momentum

The attachment amproblem.PNG is no longer available

I realize that i need to have accurate prediction to make my ragdoll balancing really robust.
My idea is to control the hip joint for example, treat all upper bodies as a single body, do the same for the lower bodies, and the see how the joint between then can affect linear / angular velocity of the entire ragdoll.
To test that idea i made that two sphere ragdoll with a single joint as an approximation.

Now to my problem, which is similar like asking for: "How can i calculate ball socket joint with powered rotation forces myself - i do not want to use newtun joint for that purpose".
The idea that i have is simple:

1. Leave the parent body fixed and calculate the child bodys animated transform.
(In image the parent is the upper sphere, white line points to the animated child bottom sphere center)

2. Calulate difference from the current to the animated center of mass (treating both bodies as a single one),
this offsets the white lines to the red lines. So, no linear motion happens and linear momentum is conserved successfully

3. Do the same for angular stuff, so i can rotate the red lines to the green lines, which would be correct because both bodies have equal mass.
To do that i treat both bodies as one again and now i need to find the correct rotation around its com, and that's where i've got stuck.

What i actually do is this (Note that i treat both spheres as point masses with uniform inertia for now.):

Code: Select all
`sVec3 tU = sVec3(comU - com).Cross(comU - comUa) * massU;sVec3 tL = sVec3(comL - com).Cross(comL - comLa) * massL;   sVec3 angularErrorVector = tL + tU;`

where comU - com is vector from com to upper sphere, and comU - comUa is the 'force' from actual position to the animated 'red state' position.
Doing that for both upper and lower sphere and summing up i hope i get some averaged error rotation information, that i need to apply the opposite way to fix it.

Next i build inertia information because both bodies are treated as a single body:
Code: Select all
`sVec3 axis = angularErrorVector.SafeUnit(); // unit direction from errorfloat inertia = 0;sVec3 d = comL - com;   inertia += massL * sVec3(axis * axis.Dot (d) - d).SqL(); // SqL = squared lengthd = comU - com;   inertia += massU * sVec3(axis * axis.Dot (d) - d).SqL();`

where i sum up point mass * squared distance of point mass from rotation axis for each sphere.

And then i caluculate final rotation angle:
Code: Select all
`float angle = angularErrorVector.Length() / inertia;`

...but it does not work - it's not so bad, it fails 50% at large angles, so i think i'm not totally wrong.
What i've tried is using current / animated average for inertia calculation: d = 0.5 * (comL+comUa) - com
That's pretty good and fails only at angles > 90 deg, making me think i need to integrate inertia over the full arc somehow.
But there should be a simple solution for that problem.

Any help very appreciated!

EDIT:
I found a solution that works even for cases where both bodies have different masses and joint is not at the center.
I can predict exactly now what the newton joint will do, but i think my solution is not general and will not work for more than 2 bodies.
I'm still interested in this issue because i see a lot of applications and wanna understand the inertia better.
I think i should rephrase the question for better understanding - hopefully:

I have a set of point masses, which are constrained to stay fixed in relation to each other, thus i can treat them as a closed system - a single rigid body.
If i change their relation, for example by moving one point mass, how can i conserve momentum of the whole set?
Attachments
amproblem.PNG (21.51 KiB) Viewed 1752 times

JoeJ

Posts: 1160
Joined: Tue Dec 21, 2010 6:18 pm