Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

## assimp-discussions

 [Assimp-discussions] aiQuaternion::Rotate() and GetMatrix are inconsistent From: Stefan Schwarzer - 2013-10-14 19:53:48 ```Hi out there, I am using libassimp 3.0 (debian testing) and stumbled across inconsistent behavior of quaternion based rotation. int main() { aiVector3D z(0,0,1); aiQuaternion roty(aiVector3D(0,1,0),M_PI/2.); std::cout << roty.Rotate(z) << std::endl; // overloaded operator<< for aiVector3D std::cout << roty.GetMatrix() * z << std::endl; } Apart from numerical inaccuracies, I expect(ed) the result of the rotation being the same in the two cases. However, it seems that the quaternion rotation is actually by an angle of -M_PI/2 around the y axis and only the matrix multiplication result corresponds to the (expected) 'active' rotation of z around y by M_PI/2. The output of the code is (-1 0 0) (1 0 5.96046e-08) I dug further into the code and found this routine for the quaternion rotation (quaternion.inl): template inline aiVector3t aiQuaterniont::Rotate (const aiVector3t& v) { aiQuaterniont q2(0.f,v.x,v.y,v.z), q = *this, qinv = q; q.Conjugate(); /// ??? q = q*q2*qinv; return aiVector3t(q.x,q.y,q.z); } This function seems to be buggy. If q.Conjugate() in the second is replaced by qinv.Conjugate() then the result of the Rotation operation is more in line with expectations. First, rotation will now happen in the same direction as by multiplication with the matrix from GetMatrix(), second compounding two rotations as qnew = qupdate * qold and then calling qnew.Rotate() will correctly produce the same result as qupdate.Rotate(qold.Rotate(z)). And third, the math would correspond to the stated intent in the line q = q * q2 * qinv. Imho the Rotate routine should be changed accordingly. Cheers, Stefan. ```
 Re: [Assimp-discussions] aiQuaternion::Rotate() and GetMatrix are inconsistent From: kim kulling - 2014-02-26 09:48:13 Attachments: Message as HTML ```Hi, sorry for the late response. I opened https://github.com/assimp/assimp/issues/225 for this bug. Thanks a lot, we really appreciate this! Kimmi On Mon, Oct 14, 2013 at 9:53 PM, Stefan Schwarzer wrote: > > Hi out there, > > I am using libassimp 3.0 (debian testing) and stumbled across inconsistent > behavior of > quaternion based rotation. > > int main() { > > aiVector3D z(0,0,1); > aiQuaternion roty(aiVector3D(0,1,0),M_PI/2.); > > std::cout << roty.Rotate(z) << std::endl; // overloaded > operator<< for aiVector3D > std::cout << roty.GetMatrix() * z << std::endl; > } > > Apart from numerical inaccuracies, I expect(ed) the result of the rotation > being the same in > the two cases. However, it seems that the quaternion rotation is actually > by an angle of -M_PI/2 > around the y axis and only the matrix multiplication result corresponds to > the (expected) 'active' > rotation of z around y by M_PI/2. The output of the code is > > (-1 0 0) > (1 0 5.96046e-08) > > I dug further into the code and found this routine for the quaternion > rotation (quaternion.inl): > > template > inline aiVector3t aiQuaterniont::Rotate (const > aiVector3t& v) > { > aiQuaterniont q2(0.f,v.x,v.y,v.z), q = *this, qinv = q; > q.Conjugate(); /// ??? > > q = q*q2*qinv; > return aiVector3t(q.x,q.y,q.z); > > } > > This function seems to be buggy. If q.Conjugate() in the second is > replaced by qinv.Conjugate() then > the result of the Rotation operation is more in line with expectations. > First, rotation will now > happen in the same direction as by multiplication with the matrix from > GetMatrix(), second > compounding two rotations as qnew = qupdate * qold and then calling > qnew.Rotate() will correctly > produce the same result as qupdate.Rotate(qold.Rotate(z)). And third, the > math would correspond to > the stated intent in the line q = q * q2 * qinv. > > Imho the Rotate routine should be changed accordingly. > > Cheers, > > Stefan. > > > > > ------------------------------------------------------------------------------ > October Webinars: Code for Performance > Free Intel webinars can help you accelerate application performance. > Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most > from > the latest Intel processors and coprocessors. See abstracts and register > > http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk > _______________________________________________ > Assimp-discussions mailing list > Assimp-discussions@... > https://lists.sourceforge.net/lists/listinfo/assimp-discussions > ```