Question

Wolfram Alpha tells me that q=(7.0711e-01,1.5272e-16,-7.0711e-01,0e+00) is one rotation, and the result makes sense in the context of the data used to generate the quaternion (analytic least squares point based registration on some simple test data...).

My code gives me a different answer, but I am stumped as to why. I've been over my code a couple of times, but I haven't spotted anything. That could just be me needing sleep, and it might be super obvious tomorrow, but I'm not sure.

Code:

// given a column vector q known to be a unit quaternion
double xx = q[0]*q[0], xy = q[0]*q[1], xz = q[0]*q[2], xw = q[0]*q[3];
double yy = q[1]*q[1], yz = q[1]*q[2], yw = q[1]*q[3];
double zz = q[2]*q[2], zw = q[2]*q[3];

arma::mat rotation;

// yes, I know I could get rid of some of these multiplications
rotation << (1 - 2 * yy - 2 * zz) << (2 * xy - 2 * zw) << (2 * xz + 2 * yw)
     << arma::endr
     << (2 * xy + 2 * zw) << (1 - 2 * xx - 2 * zz) << (2 * yz - 2 * xw)
     << arma::endr
     << (2 * xz - 2 * yw) << (2 * yz + 2 * xw) << (1 - 2 * xx - 2 * yy)
     << arma::endr;

// and now I have the wrong result

My result:

-2.2204e-16   2.1598e-16  -1.0000e+00
 2.1598e-16  -1.0000e+00  -2.1598e-16
-1.0000e+00  -2.1598e-16   2.2204e-16

Wolfram Alpha's result

Was it helpful?

Solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top