Maths - Matrix to Quaternion - Use of copysign

Paul sent me the following issue with the use of copysign in Christians alternative method which is described on this page. Since I don't have much expertise with C++ code and haven't used copysign myself I will pass on Pauls comments:

The article mentions an alternative method using _copysign(x,y) but a common behavior of this function is to return (+1) when y=0 given the following matrix

1 0 0
0 1 0
0 0 -1

this alternate method produces different results

Q.x = sqrt( max( 0, 1 + m00 - m11 - m22 ) ) / 2;
Q.x = _copysign( Q.x, m21 - m12 )

producing Q.x = 0.7071068 whereas the original algorithm:

qx = (m21 - m12) / ( 4 *qw )

here it is clear that when (m21 - m12) equals (0) then (qx) will be zero if you use a version of copysign that returns +1,0,-1 then it might work.

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.


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

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