**1**

# Quaternions concatenation is the sum of angles ?

Started by hbdevelop1, Nov 28 2012 08:01 AM

5 replies to this topic

###
#1
Members - Reputation: **113**

Posted 28 November 2012 - 08:01 AM

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

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

Sponsor:

###
#3
Members - Reputation: **307**

Posted 28 November 2012 - 08:19 AM

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)

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, 28 November 2012 - 08:38 AM.**

###
#4
Members - Reputation: **113**

Posted 28 November 2012 - 08:43 AM

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

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

###
#5
Members - Reputation: **307**

Posted 28 November 2012 - 08:46 AM

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/

Quaternions have float components. You CAN'T compare floats directly.

Please read this:

http://floating-point-gui.de/

###
#6
Members - Reputation: **113**

Posted 28 November 2012 - 09:21 AM

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

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