Jump to content

  • Log In with Google      Sign In   
  • Create Account

How to calculate angular momentum?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 20 December 2013 - 09:20 PM

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:

 

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:



Sponsor:

#2 Khatharr   Crossbones+   -  Reputation: 3007

Like
0Likes
Like

Posted 22 December 2013 - 12:28 PM

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.

#3 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 22 December 2013 - 02:39 PM

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.


Edited by Hawkblood, 22 December 2013 - 02:40 PM.


#4 Khatharr   Crossbones+   -  Reputation: 3007

Like
0Likes
Like

Posted 22 December 2013 - 11:51 PM

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, 22 December 2013 - 11:53 PM.

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.

#5 Hawkblood   Members   -  Reputation: 723

Like
0Likes
Like

Posted 23 December 2013 - 01:00 PM

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

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



#6 Khatharr   Crossbones+   -  Reputation: 3007

Like
0Likes
Like

Posted 23 December 2013 - 08:13 PM

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.

#7 Khatharr   Crossbones+   -  Reputation: 3007

Like
0Likes
Like

Posted 24 December 2013 - 09:04 AM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS