# Maths - Conversion Matrix to Axis Angle - Forum Discussion

 Minor Correction to Matrix to AxisAngle By: Andreas Keil (akeil) - 2007-06-13 14:10 Hi Martin,    first of all, thanks a lot for your effort in putting up this really huge website (in terms of contained information). I used a few of your conversion routines and during testing them I think, I found a small bug in the Matrix to AxisAngle conversion:    The special case of a 180° rotation around one of the basis vectors is not handled correctly. The test  Abs(m01+m10)<0.001 and Abs(m02+m20)<0.001 and Abs(m12+m21)<0.001  or  if (Math.abs(m01+m10)

 RE: Minor Correction to Matrix to AxisAngle By: Martin Baker (martinbaker ) - 2007-06-14 08:00 Hi Andreas,    Thanks for you comments on the website, its fun to do, some parts of the site aren't as good as I'd like but its improving all the time with the help of yourself an the people on this forum.    You've given me some things to think about here. The first thing is: should we assume the input matrix is a pure, orthogonalised, rotation matrix and can we discount, for instance, a reflection matrix? I am tempted to include a optional calculation of the determinant at the start of the algorithm, if its +1 then that would be a good indication that its a rotation and if -1 its likely to be a reflection. If its not a rotation then an exception could be raised.    So if its a rotation and not a reflection then I think that means we can discount the case with an odd number of negatives in the leading diagonal? So we only have to test the leading diagonal for:  3 plus ones = identity matrix  1 plus one and two minus ones = 180 degree rotation.    I think thats what your suggested code does but I'll take a bit more time to work it through.    I should have lots of time to work on the site soon so I'll look at this and the issues raised by Paolo de Leva and Xavier.    Thanks,    Martin

 RE: Minor Correction to Matrix to AxisAngle By: Andreas Keil (akeil) - 2007-06-15 04:25 Hi Martin,    since the part of your web page we are talking about is on (proper) rotations, and since all other representations (except matrices) are not able to describe improper rotations / reflections, I would assume a pure rotation matrix. Anyways, there would be more checks necessary in order to decide whether a 3x3 matrix represents a rotation (R'*R = I and det(R) = 1 would be the complete test) and this in every of your conversion methods from matrix to anything. In my own C++ code, I included an assert(isRotationMatrix(R)) which is only evaluated in debug mode and does not affect performance in release mode.    As to my proposed code change: You are absolutely right with your interpretation: Your conditions on this line of code so far are met by the identity matrix as well as 180deg rotations around one of the three basis axes. Since you only want to handle the identity matrix in the if-case, you have to add this condition. The 180deg basis rotations are then handled by the else-case.    I would only sort out the identity case with the additional trace(M) = 3 check. Other additional checks would only increase the computation time here and if you wanted to stop on reflections, you would really have to do the full checks (R'*R=I and det(R)=1) at the very beginning of the conversion routine.    Cheers,  Andreas.