# Quaternions concatenation is the sum of angles ?

## Recommended Posts

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 ?

##### Share on other sites
Edit: Sorry, disregard... Edited by Olof Hedman

##### Share on other sites
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 on other sites
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 on other sites
I think the problem is with your comparision code.
Quaternions have float components. You CAN'T compare floats directly.
http://floating-point-gui.de/

##### Share on other sites
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;
}

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628305
• Total Posts
2981967

• 9
• 13
• 11
• 12
• 11