This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Quaternion equality test

Tags: None
(comma "," separated)
arennuit
Registered Member
Posts
28
Karma
0

Quaternion equality test

Fri Nov 29, 2013 5:48 pm
Hello,

I have noticed there is no test for quaternions equality which is defined (e.g. something like operator==(...) or an 'isEqualTolerance(..., Scalar tolerance = (Scalar)1e-3)').

Is there a good reason for that or is it just something to add one day in the future?

Of course I understand I can customize the class and add the function / operator myself. I only ask to understand whether it is a good idea to do so or whether there is a trick ;)

Thanks,

Antoine.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Quaternion equality test  Topic is solved

Fri Nov 29, 2013 9:20 pm
There is an isApprox method that compares the quaternion's coefficients: q1.isApprox(q2). If you want to compare the orientations represented by the quaternions you can use the angularDistance function q1.angularDistance(q2)<epsilon, or even q1.dot(q2)>1-epsilon which avoids a trigonometric function.
arennuit
Registered Member
Posts
28
Karma
0

Re: Quaternion equality test

Sat Nov 30, 2013 7:53 am
This is great, thanks!
johnm1019
Registered Member
Posts
46
Karma
0

Re: Quaternion equality test

Sat Dec 07, 2013 4:22 pm
slight follow up here. I am storing orientations and want to ensure I only store unique quaternions. As each quaternion has 2 possible representations I wanted to chose the one with W > 0. Is there a cleaner way to negate all the components?
Right now I have to do
quat.w() *= -1;
quat.x() *= -1;
quat.y() *= -1;
quat.z() *= -1;
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Quaternion equality test

Sat Dec 07, 2013 10:38 pm
quat.coeffs() *= -1;

or

quat.coeffs() = -quat.coeffs() ;
johnm1019
Registered Member
Posts
46
Karma
0

Re: Quaternion equality test

Sun Dec 08, 2013 1:27 pm
ggael wrote:quat.coeffs() *= -1;

or

quat.coeffs() = -quat.coeffs() ;


Thanks. Sorry I missed that in the docs


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]