# combining rotational forces

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

## Recommended Posts

I'm developing a somewhat simple physics engine that can deal with most real world events such as collisions and what not. One small problem I'm having is rotational forces and such. Let's say I have a tree in free space. If I apply a force at the end of the tree it should start spinning. For now, we're going to assume the tree's center is fixed and not moveable. So far so good. I can also spin the tree about it's up axis. So now it's spinning around its up axis AND also spinning about a side to side axis. I don't know if it's even possible to spin it about 3 axises at once. But what I'm trying to get at is how do I represent this with math? I was thinking of storing rotational forces as vectors to spin about and the forces to push at. Then somehow add them all up and apply the final force. But like I just explained, it's possible to rotate something multiple ways at once. Does anyone have any ideas of how to tackle this problem? EDIT: To be honest, I might be wrong. The tree I described might actually be rotating on one axis, but because it is long it only seems to be rotating on completely different axises. Am I right here? Is my method of simply adding up all the rotational forces and applying it the tree correct? [Edited by - tendifo on July 4, 2006 8:32:52 PM]

##### Share on other sites
Handling rotational motion is a bit tickier than linear motion, but not conceptually very different. Look up angular momentum, angular velocity, and inertia tensor on wikipedia. See if that helps at all. Good luck!

##### Share on other sites
I understand the concepts of rotational velocity, torque, and what not. The thing I'm having trouble figuring out is how to deal with multiple external torque forces from different directions.

Take my tree as an example. Assume Y is up, Z is towards the horizon, and X is to the right. I can start spinning it about the Y-axis, but then after a few seconds, tap it at it's base and start spinning it about the X axis. It is now spinning about two axises. I'm confused as to how to deal with that scenario.

Thanks.

##### Share on other sites
The tricky bit isnt so much dealing with the torques, but in representing a rotation in 3 dimensions. You seem to have intuitively stumbled on the problem of "gimble lock" where you can lose an axis of rotation due to the object flipping about.

I would suggest you look into the different ways 3d rotations can be stored. In a matrix or a quaternion. Also you may want to look up axis-angle representation. I think when you become familiar with these, it will start to make some sense. There are many articles on this very site dealing with these concepts.

##### Share on other sites
My understanding is that you integrate torque to give you angular momentum. You combine this with the mass & inertia tensor to get angular velocity, which you can store as a 3 vector and a scalar.

The 3 vector is the axis of rotation, and the scalar is the amount and direction of spin around that axis.

To combine the new rotation ( due to the new torque or rotational impulse applied ), with the old one, is very easy.

vector3 old1( mAxisOfRotation *  // vector              mAngularVelocity );  // scalarvector3 new1( new_axis_of_rotation *  // vec             new_angular_speed );   // scalarold1 += new1;  // combine themmAngularSpeed = vec3length( &old1 );  // extract new speedmAxisOfRotation = vec3normalize( &old1 );  // extract new axis

Then, you can apply the angular velocity by turning this into a quaternion, etc.

##### Share on other sites
SimmerD, I'm confused as to why you're adding the new angular velocity to the old angular velocity. That shouldn't be necessary.

Tendifo, all you need to do is this. Store the orientation, angular momentum, and inertia tensor for the tree. Whenever a torque is applied, add the torque vectorially to the angular momentum. The angular momentum vector will remain constant when no torque is applied. (This is NOT true about the angular velocity vector, also known as the axis of rotation.) Finding the angular velocity vector can be tricky, due to changing coordinate systems. In any consistent coordinate system however, (inertia tensor)*(angular velocity vector) = (angular momentum vector). Once the angular momentum vector has been found, use quaternion rotation or something to rotate the object, as has already been explained.

##### Share on other sites
Hmm, well I've obviouslly stumbled upon a very complex topic. A 3D physical world is something I shouldn't really try to do now.

I'm going to develop a simpler 2D physical world where angular momemtum and speed and what not are in one dimension, not multiple.

And then if I can get that working, I'll move back to 3D.

Thanks for all the help.

##### Share on other sites
I found an excellent source on physics engines and simulators.

http://www.cs.cmu.edu/~baraff/pbm/pbm.html

More specifically, the link labeld "Rigid Body Dynamics I."

I read his article up to the coding about 3 times, took notes.. I got it.. well most of it. At least up to the end. I don't really understand how this all falls together. I'm just gonna ramble on for a while describing what I understand. If I get anything wrong someone please tell me.

So this, I completely understand:

p(t) = R(t) * p0 + x(t)

And I understand this idea:

P(t) = M * v(t)

So I can rewrite it to this:

v(t) = P(t) / M

Then alter the x(t) of the body accordingly. He suggests integrating v(t) over the time interval, which is a rather good idea actually.

What I do not understand at all is how I convert angular momentum, intertia tensors, and the like into an angular velocity and eventually alter the R(t) matrix to finally rotate the body.

He writes also (he uses a dot above the variable to denote a derivative.. I'm using a prime here):

R'(t) = w(t)* R(t)

where w(t)* is equal to some matrix that replaces cross products. Alright so I get that.

He defines w(t) as:

w(t) = I(t) * L(t)

L is the momentum. He defines it as:

L(t) = I(t)w(t)

But here is where I get confused... it's more or less circular math here as far as I can tell.. but..

He also writes:

L'(t) = torque(t)

So do integrate torque over time to get the momentum?

I don't really understand how he comes to this:

I = R(t) * Ibody * R(t)^T <--- ^T is transposing the matrix, I know.

Can someone explain Ibody?

But nevertheless, you multiply those matrices together to get w(t) and then replug into the one equation to get R'(t).. then integrate it over the time interval and get the new R(t)? Is that right?

Can anyone shed some light who's read this article and/or understands this topic more than I do? I'll continue to look at the math.

Thanks a bunch.

##### Share on other sites
The Baraff papers are a standard reference on the topic, so you're in good shape there :-)

Just a couple of comments. Force is the derivative of linear momentum (as you may already know), and torque is the derivative of angular momentum. All of these are vector quantities (in 3D at least).

Furthermore, linear velocity is the derivative of position, and angular velocity is related to the derivative of orientation (yes, it's a bit confusing).

The next piece of the puzzle is the relationship between momentum and velocity. Linear momentum and velocity are related via mass (a scalar), and angular momentum and velocity are related via the inertia tensor (a 3x3 matrix), which can be said to be the angular equivalent of mass, more or less.

The former relationship is easy: linear_velocity = linear_momentum / mass.

The latter is trickier because we can't divide by a matrix. We can however multiply by the inverse, which gives:

angular_velocity = inertia_tensor^-1 * angular_momentum

(Note that I'm using column vectors as per Baraff's convention).

The next tricky part is that the inertia tensor has to be in world space (assuming the other quantities are in world space) for this equation to work, and updating a world-space inertia tensor as the object moves can be expensive.

The solution is to use a similarity transform, in which we:

1. Transform the angular momentum vector into the local space of the object
2. Apply the inverse inertia tensor in local space
3. Transform the angular momentum vector back into world space

Which looks something like this:

w = R*I_local^-1*R^T*L

This way, the inverse inertia tensor can be computed once, in local space, and used from there on without any expensive recomputations (provided the shape or mass distribution of the object doesn't change).

Finally, it's time to update the orientation (a 3x3 matrix, although it can also be done using quaternions) given the angular velocity w (assuming I'm remembering my abbreviations correctly). For this we can address each of the three orthonormal basis vectors of the rotation matrix separately, and note that the instantaneous linear velocity of each is related to w via the cross product. This post is long enough, so we'll skip over the rest and just point out that the skew-symmetric ('star') matrix derived from w essentially performs this cross-product operation with each basis vector all in one go. After updating the orientation matrix, you re-orthogonalize it to correct the (inherent) inaccuracy associated with this method.

To disclaim, I'm not a physics pro and only have the most basic understanding of these topics, so take all of the above with a grain of salt. Make sure to compare what I've written here with the references you're studying, as I could have easily made some errors.

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631719
• Total Posts
3001886
×