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 matrix.Invert(inertia_world) 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?