# How to calculate angular momentum?

This topic is 1642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If you are inside a space ship that is spinning and you step out the air lock, you would go in a straight line away from the ship but you would have the same "spin" as the ship. Here is a video showing how it's NOT supposed to look:

[media]http:

[/media]

What I want to know is how to retrieve the rotational information that the ship has and apply it to the space suit.

Here's a better example:

[media]http:

[/media]

##### Share on other sites

It's only a slightly complex case of conservation. You need to calculate the angular momentum of the complete system (ship + astronaut), then divide it according to the mass of the two objects. Momentum is velocity * mass. So add the mass of the ship and the astronaut, then multiply that by the rotational velocity to get the angular momentum of the system. Divide that between the two objects by their mass:

astronaut_momentum = total_momentum * astronaut_mass / total_mass

Then divide the astronaut's momentum by his mass to get his angular velocity. A little bit of algebra can simplify that into a simple algorithm. Technically the ship should lose the momentum that the astronaut 'takes' from the system, but for a ship of any reasonable size it's probably negligable.

##### Share on other sites

Let me clarify:

I control the ship's rotation using a quaternion. Each frame I pass yaw, pitch, and roll values to the ship telling it by how much it should YPR. If the ship is spinning like in the video, then only roll is not equal to 0. I need to be able to set the space suit's YPR to what the ship's is.

The problem is that I can't seem to get any useful quaternion information to apply to the space suit.....

I think I have it!!!

Here is a snippet:

				ActorController.Actors[A].rotQuat=ShipController.Ship[0].RotQuat*ActorController.Actors[A].rotQuat;
//what is the angular momentum components
D3DXMATRIX tmp;
D3DXVECTOR3 rotV;
rotV.x=ShipController.Ship[0].YPRQuat.x;
rotV.y=ShipController.Ship[0].YPRQuat.y;
rotV.z=ShipController.Ship[0].YPRQuat.z;
D3DXMatrixRotationQuaternion(&tmp, &ShipController.Ship[0].RotQuat);
tmp(3,0) =0;
tmp(3,1) =0;
tmp(3,2) =0;
D3DXMatrixInverse(&tmp,0,&tmp);
D3DXVec3TransformCoord(&rotV,&rotV,&tmp);
D3DXMatrixRotationQuaternion(&tmp, &ActorController.Actors[A].rotQuat);
tmp(3,0) =0;
tmp(3,1) =0;
tmp(3,2) =0;
D3DXVec3TransformCoord(&rotV,&rotV,&tmp);



Basically, I stored the rotation of the ship in YPRQuat (from the current frame) and when the space suit "exits the airlock", this code happens.

It stores the YPR in a vector. Then un-rotate the vector using the ship's rotation quaternion. Then rotating the vector using the composite rotation quaternion. And finally, storing the values in the YPR floats.

Edited by Hawkblood

##### Share on other sites

Can you show how you're composing the quat from YPR values? YPR is Euler rotation. Quaternions use a whole different paradigm, which would make this calculation linear and exceedingly simple. If you're doing what I think you're doing then there's an easier solution to this. (As in - one very simple line of code.)

Edited by Khatharr

##### Share on other sites
D3DXQuaternionRotationYawPitchRoll(&YPRQuat, heading, pitch, roll);


heading, pitch, and roll are (in radians) the amount of YPR to go each frame.

##### Share on other sites

lol, okay. I didn't know d3dx had that function. I thought you were doing it manually.

If the values you're feeding to that represent axis-oriented angular velocities then just:

float ratio = suitMass / totalMass;

D3DXQuaternionRotationYawPitchRoll(&suitYPRQuat, heading* ratio, pitch* ratio, roll * ratio);

##### Share on other sites

~posted nonsense here, then changed my mind~

1. 1
2. 2
3. 3
4. 4
Rutin
16
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999965
×