Sign in to follow this  
hbdevelop1

Quaternions concatenation is the sum of angles ?

Recommended Posts

hbdevelop1    113
Hello,

With the two quaterions q1=q2=(pi/8, 1, 0, 0)
Does the product q1q2 yield a third quaternion q3 equal (pi/4, 1, 0, 0) ?

This is the result I am expecting to have from my quaternion class, but I don't have it.
My expectation is based on the fact that the concatenation of q1 and q2 will yield a quaternion representing both rotations. That means, for me, the sum of the angles each quaternion represents if the rotations are around the same vector.

So, does the product q1q2 yield a third quaternion q3 equal (pi/4, 1, 0, 0) ?
Or is there anything wrong with my assumption ?

Thank you in advance

Share this post


Link to post
Share on other sites
teccubus    307
Quaternion (pi/8, 1, 0, 0) does not represent rotation you wanted.
Quaternion for rotation by an angle theta around an axis A is computed by this formula:
q = (cos theta/2, Ax sin theta/2, Ay sin theta/2, Az sin theta/2) Edited by teccubus

Share this post


Link to post
Share on other sites
hbdevelop1    113
Oh! Yes, you are right.
I was thinking of my code while writing the email.
Because my code looks like :

HQuaternion q1(PI_over_8,HVector3(1,0,0));
HQuaternion q2(PI_over_8,HVector3(1,0,0));
HQuaternion r1=q1*q2;
HQuaternion q3(PI_over_4,HVector3(1,0,0));
assert(r1 == q3);

Please respond my second email "Quaternions concatenation is the sum of angles ? (2)"

Thank you

Share this post


Link to post
Share on other sites
teccubus    307
I think the problem is with your comparision code.
Quaternions have float components. You CAN'T compare floats directly.
Please read this:
http://floating-point-gui.de/

Share this post


Link to post
Share on other sites
hbdevelop1    113
I found out my error when I was trying to write my respond explaining that I am doing nothing wrong !

My product operator expects a quaternion class constructor with the W component as a first parameter.
While the available constructor expects an angle as the first parameter.

HQuaternion HQuaternion::operator*(HQuaternion & q)
{
return HQuaternion(
w*q.w - v.Dot(q.v),HVector3(q.v*w + v*q.w + v.Cross(q.v) )
);
}
HQuaternion::HQuaternion(double angle, HVector3 & _v):v(_v)
{
double angleover2 = angle/2;
double c = cos(angleover2);
double s = sin(angleover2);
v.Normalize();
w=c;
v *= s;
}

Thank you for your responses and for the link

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this