I have a pretty simple rigid body simulation written in Python. In my code I calculate the angular acceleration using formula:

angAcc = torque * inertiaTensor^-1 (note row-major matrix order)

Now, the torque is in world-space so my inertiaTensor should also be in world-space. My Python code that does the angular acceleration computation looks like this:

oriMat = quaternion.ToMatrix(self.ori)
inertia_world = self.inertia_local * oriMat
angAcc = vector.Transform(self.totalTorque, inertia_world)

oriMat is effectively local-to-world transform. self.totalTorque is torque in world space. So this code transforms local inertia to world inertia and uses its inverse along with world torque to compute world angular acceleration. This code works completely fine.

I thought to check out if I could conduct the angular acceleration compuation in local space and eventually convert local angAcc to world angAcc. Here's the code:

oriMat = quaternion.ToMatrix(self.ori)
self.totalTorque = vector.Transform(self.totalTorque, matrix.Inverted(oriMat))
angAcc = vector.Transform(self.totalTorque, matrix.Inverted(self.inertia_local))
angAcc = vector.Transform(angAcc, oriMat)

Here I wanted to do the torque-inertia transform in local space. To do so, I transform self.totalTorque to rigid body's local space using inverse of oriMat. Then I mul that by inverted local inertia to get angular acceleration in local space. Finally, I transform angular acceleration to world space by transforming it with oriMat.

For some reason this code doesn't yield correct behaviour of my rigid body and I really can't tell why. Anyone got an idea?


You say :

Then I mul that by inverted local inertia to get angular acceleration in local space.

This seems wrong, since "inverted local inertia" is "world inertia", so you are putting "that" to world space while you want it in local space ...

So code should be :

// oriMat: local -> world
oriMat = quaternion.ToMatrix(self.ori)

// put total torque in local space
self.totalTorque = vector.Transform(self.totalTorque, matrix.Inverted(oriMat))

// multiply local torque with local inertia to get angAcc in local space
angAcc = vector.Transform(self.totalTorque, self.inertia_local))

// put angAcc in world space
angAcc = vector.Transform(angAcc, oriMat)
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.