How to calculate angular momentum?

Started by
5 comments, last by Khatharr 10 years, 3 months ago

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]

Advertisement

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.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

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);

				ActorController.Actors[A].Padd=rotV.x*2.0f;
				ActorController.Actors[A].Yadd=rotV.y*2.0f;
				ActorController.Actors[A].Radd=rotV.z*2.0f;

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.

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.)

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

D3DXQuaternionRotationYawPitchRoll(&YPRQuat, heading, pitch, roll);

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

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);

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

~posted nonsense here, then changed my mind~

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement