# Torque and Angular Momentum

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

## Recommended Posts

Hello,

I am currently in the process of developing angular momentum for my game, and I am implementing torque for the purposes of changing objects' angular momentum.

If I understand torque correctly, it is calculated by the position vector (R) (position the force is applied relative to the object) with the cross product of the force vector (F).  The torque is then added to the angular momentum, resulting in the object starting to rotate.

The angular momentum vector determines the direction the object rotates.  An angular momentum vector of [0, 1, 0] should then cause an object to rotate to the left (it would spin counter-clockwise).

So, to get an object to spin to the left, one would apply a force of [0, 0, 1] to the position of [1, 0, 0] (e.g. a force going forward applied to the right of the object).  Positive X is to the right, and positive Z is going forwards.

However, when I calculate R x F (e.g. [1, 0, 0] x [0, 0, 1]), I am getting torque result [0, -1, 0], which would cause the object to rotate clockwise instead of counter-clockwise.  I figured my cross product calculation was wrong, but even Wolfram Mathematica gives me the same result.

Am I missing something?  Even the animations on Wikipedia's explanation of what torque is demonstrates that a force applied to the right of an object causes it to spin to the left (the animation clearly shows the vectors, and the torque vector is going upwards).  Not to mention, this is what happens in real life.

Is there something different about the coordinate system being used?

##### Share on other sites

So, it appears that I am using a left-handed coordinate system, and the cross product in such a system always goes the opposite direction (you can see such an explanation here: https://betterexplained.com/articles/cross-product/).  In my example above, in the right-handed coordinate system (positive X is to the left, positive Y is straight ahead, and positive Z is straight up), I would be calculating [1, 0, 0] cross [0, 1, 0], yielding [0, 0, 1], which looks correct.  If I use the left-handed version of the cross product, I will get the correct result of [0, 1, 0] for the angular momentum vector.

Weird that different coordinate systems even exist at all.  I have always worked with the left-handed system in game development.

Now I will have to replace all of my cross product calls with a special 'cross_lh' version, as my entire game engine has been unknowingly developed in this left-handed system.

##### Share on other sites
1 hour ago, Eleventy said:

Now I will have to replace all of my cross product calls with a special 'cross_lh' version, as my entire game engine has been unknowingly developed in this left-handed system.

You can only switch the operands, so cross(b,a) instead cross (a,b).

It's a convention issue but not wrong. Similar things may happen on matrix multiplication order, column major vs. row major, etc.

##### Share on other sites

Ah, I realize now why I have seen some other tutorials have the cross products reversed - given that the cross product is not commutative, that never made much sense to me until now.

Good to know that matrices (and perhaps other components) also have this same issue.

Now that I think about it, I did have to do some weird logic calculating the "look at" matrix and reverse all of the Z coordinates in order for my scene to even render and for movement to work correctly to begin with, as OpenGL and Metal is apparently configured to use a right-handed projection matrix by default (with no known way to change it).

##### Share on other sites

Usually it should not matter if you are left or right handed to build a look at matrix (altough it's common you flip one axis on model import).

If your world is left handed, you calculate the look at there and submit all your left handed matrices unchanged to GL - the look at should work.

The only thing going wrong is that everything is flipped like you see the world in a mirror, which is why you flip one axis at model load. (Painting the letter F to textures may help). But a guy looking at a girl still looks at her if you see them in a mirror.

So this may indicate something else is wrong, like using column major code for row major matrices, or the code returns camara to world but you expect world to camera result.

Here are some common pitfalls and their work arounds:

Column major vs. row major: transpose the matrix or change indexing code.

Multiplication order: a*b -> b*a (for both m*m and m*v)

Handness: As above, only things like matrix <->quaternion will go really wrong if convention does not match.

Euler angles: Figure out their order of rotations.

Cross product: The order changes only the sign, but both results lie on the same line and magnitute is the same as well.

Edited by JoeJ

##### Share on other sites

I will look through my code and see where there might be one of those pitfalls you mentioned happening, as I do not feel that having to flip both the X and Y axis on the 'forward' vector and the Z-axis on the 'up' vector for the look-at matrix, in conjunction with having to flip all Z components of the position vectors for everything in my world is indication that I am doing everything right.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633701
• Total Posts
3013440
×