## Is diagonlize/extractRotation broken, i.e., does nothing? see 3 lines of example code and try yourself

stephenop
Posts: 4
Joined: Mon Apr 30, 2018 3:36 pm

### Is diagonlize/extractRotation broken, i.e., does nothing? see 3 lines of example code and try yourself

Example inertia tensor:
0.00076275 -0.00047298 0
-0.00047298 0.0019185 0
0 0 0.0022293

btMatrix3x3 inertia(0.00076275, -0.00047298, 0, -0.00047298, 0.0019185, 0, 0, 0, 0.0022293);
btQuaternion q = btQuaternion::getIdentity();
inertia.extractRotation(q);

The omega computed in extractRotation is 0 on the very first iteration of the loop resulting in exiting. This basically just returns your identity quaternion.... This function has been in bullet for a long time I'm hoping I'm just doing something wrong but...

Omega computes the sum of cross product of the columns of the identity q and the inertia tensor. This result in 0,0,0 since you get 0,0,-0.4730
+ 0,0,0.4730 and 0,0,0

Running eig to do vd decomp in matlab reveals correct rotation and principle axis.

drleviathan
Posts: 551
Joined: Tue Sep 30, 2014 6:03 pm
Location: San Francisco

### Re: Is diagonlize/extractRotation broken, i.e., does nothing? see 3 lines of example code and try yourself

You can't extract a valid rotation from a non-orthonormal 3x3 matrix.

Inertia tensors are 3x3 matrices but are not orthonormal in general.

What do you really want to do? Why would you be trying to extract a rotation from an inertia tensor? Are you trying to compute the rotation that would diagonalize the matrix?

Erwin Coumans
Posts: 4189
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

### Re: Is diagonlize/extractRotation broken, i.e., does nothing? see 3 lines of example code and try yourself

The original btMatrix3x3::diagonalize method should work for symmetric matrices. Recently (2017) I replaced it with a diagonalize method based on the "A Robust Method to Extract the Rotational Part of Deformations" paper and its extractRotation implementation, but the resulting rotation still includes scaling. Reverted back to original implementation in this pull request:
https://github.com/bulletphysics/bullet3/pull/1668