RotationMatrixToAngleAxis Bug?

135 views
Skip to first unread message

tobias...@web.de

unread,
Apr 11, 2014, 4:36:31 AM4/11/14
to ceres-...@googlegroups.com
I have the following rotation matrix:

-0.999807135425239    -0.0128154391194470   -0.0148814136745799
-0.0128154391194470   -0.148441438622958     0.988838158557669
-0.0148814136745799    0.988838158557669     0.148248574048196

Which yields the rotation vector (using RotationMatrixToAngleAxis)
   
0.0309
2.0499
2.3804

But correct would be
0.0309
-2.0499
-2.3804

My debugging showed that this rotation matrix leads to Case 3, the hard case. As in this case sintheta==0, the sign-changing rules won't be applied, leading to the wrong results.



The correct result was produced using the following matlab implementation:
               
% Solution by Mike Burl on Feb 27, 2007
% This is a better way to determine the signs of the
% entries of the rotation vector using a hash table on all
% the combinations of signs of a pairs of products (in the
% rotation matrix)

% Define hashvec and Smat
hashvec
= [0; -1; -3; -9; 9; 3; 1; 13; 5; -7; -11];
Smat = [1,1,1; 1,0,-1; 0,1,-1; 1,-1,0; 1,1,0; 0,1,1; 1,0,1; 1,1,1; 1,1,-1; 1,-1,-1; 1,-1,1];

M
= (R+eye(3,3))/2;
uabs
= sqrt(M(1,1));
vabs
= sqrt(M(2,2));
wabs
= sqrt(M(3,3));

mvec
= [M(1,2), M(2,3), M(1,3)];
syn  
= ((mvec > 1e-4) - (mvec < -1e-4)); % robust sign() function
hash
= syn * [9; 3; 1];
idx
= find(hash == hashvec);
svec
= Smat(idx,:)';

out = theta * [uabs; vabs; wabs] .* svec;


tobias...@web.de

unread,
Apr 11, 2014, 5:05:37 AM4/11/14
to ceres-...@googlegroups.com
The Eigen implementation works as well.

Eigen::AngleAxisd poseVecEigen;
poseVecEigen
.fromRotationMatrix(rotMatrix);
Eigen::Vector3d poseVec = poseVecEigen.axis()*poseVecEigen.angle();


Sameer Agarwal

unread,
Apr 11, 2014, 9:59:24 AM4/11/14
to ceres-...@googlegroups.com
Thanks for reporting this. I will look at it shortly.
Sameer
--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/219fc0b7-3348-460c-9390-f8ae17b3bb78%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sameer Agarwal

unread,
Apr 14, 2014, 1:07:44 AM4/14/14
to ceres-...@googlegroups.com
Tobias,

If I use eigen on the matrix you gave me, the solution is the negative of what you gave me. But that should be okay, since the rotation is exactly pi, and both a pi and a -pi rotation will give the same rotation.

I am working on a patch to fix this issue, it is going to take me a bit to get it tested properly and checked in. 

Sameer

On Fri Apr 11 2014 at 6:59:24 AM, Sameer Agarwal <sandwi...@gmail.com> wrote:
Thanks for reporting this. I will look at it shortly.
Sameer


On Fri Apr 11 2014 at 2:05:38 AM, <tobias...@web.de> wrote:
The Eigen implementation works as well.

Eigen::AngleAxisd poseVecEigen;
poseVecEigen
.fromRotationMatrix(rotMatrix);
Eigen::Vector3d poseVec = poseVecEigen.axis()*poseVecEigen.angle();


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver+unsubscribe@googlegroups.com.

armoi...@gmail.com

unread,
Jan 23, 2015, 4:23:24 PM1/23/15
to ceres-...@googlegroups.com
Hi Tobias,
I found exaclty the same issue when i compare it to matlab.
Very Best Regards
Armand

Sameer Agarwal

unread,
Jan 23, 2015, 4:24:48 PM1/23/15
to ceres-...@googlegroups.com
This is fixed in 1.10.0
Sameer


--
You received this message because you are subscribed to the Google Groups "Ceres Solver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ceres-solver...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ceres-solver/44c4d608-671e-46ee-8bcf-6b9c536b9adb%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages