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

Post Reply
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

Post by stephenop »

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.
User avatar
drleviathan
Posts: 849
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

Post by drleviathan »

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?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
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

Post by Erwin Coumans »

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

See also discussion details in the Bullet github tracker here:
https://github.com/bulletphysics/bullet ... -386286987
stephenop
Posts: 4
Joined: Mon Apr 30, 2018 3:36 pm

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

Post by stephenop »

Also, eigen decomposition or svd work fine to get the principle axis and the rotation from the inertia tensors orientation to the principle axis. Since inertia tensor are 3x3 and symmetric there is a closed form solution.

Are you trying to compute the rotation that would diagonalize the matrix?
Yes, since bullet requires principle axis instead of inertia tensor.
Post Reply