Maths - Matrix to Axis Angle - Forum Discussion

By: Gene Gorokhovsky (geneg102) - 2008-10-30 15:48

In case of Math.PI turn, if we find the largest diagonal element, only corresponding axis dimension needs to be calculated using square root, the rest can be done from the off-center elements. If, by convention, we pick the the sign of the the elements calculated from square root as positive, rest come out automatically, simplifying logic and speeding up code. This also eliminates need for checks for negative square root checks (since any normalization jitter affects only diagonal elements close to -1, and such element cannot possibly be the largest.)

The whole PI branch becomes

 if (m.m00 >= m.m11) {
  if (m.m00 >= m.m22) {
  //00 is max diag 
   x = Math.sqrt(0.5 * (m.m00+1)); 
  y = m.m01 * 0.5 / x;
  z = m.m02 * 0.5 / x;
   } else {
  //22 is max
   z = Math.sqrt(0.5 * (m.m22+1));
  x = m.m02 * 0.5 / z;
 y = m.m12 * 0.5 / z;
  }
   } else {
  if (m.m11 >= m.m22) {
 //11 is max diag 
  y = Math.sqrt(0.5 * (m.m11+1));
  x = m.m01 * 0.5 / y;
 z = m.m12 * 0.5 / y;
  } else {
 //22 is max
  z = Math.sqrt(0.5 * (m.m22+1));
  x = m.m02 * 0.5 / z;
 y = m.m12 * 0.5 / z;
  }
 }
 
 
By: Martin Baker (martinbaker) - 2008-10-31 10:45
Gene,

Thank you very much for this. I have put a link to your message on the Matrix to Axis Angle page (in a box below the Singularities heading). I hope that is alright?

I need to do some more work on this, which may take me some time, so that I can incorporate this fully into the page.

Coincidently I had noticed that this is the method used on the matrix to Quaternion page:
https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
and so I was just starting to think along these lines myself.

Cheers,

Martin

 

back to matrix to axis-angle page


metadata block
see also:

 

Correspondence about this page

Book Shop - Further reading.

Where I can, I have put links to Amazon for books that are relevant to the subject, click on the appropriate country flag to get more details of the book or to buy it from them.

cover Introductory Techniques for 3-D Computer Vision by Emanuele Trucco, Alessandro Verri

 

This site may have errors. Don't use for critical systems.

Copyright (c) 1998-2023 Martin John Baker - All rights reserved - privacy policy.