• Create Account

## Quaternions concatenation is the sum of angles ?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1hbdevelop1  Members

113
Like
0Likes
Like

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

### #2Olof Hedman  Members

5702
Like
0Likes
Like

Posted 28 November 2012 - 08:07 AM

Edit: Sorry, disregard...

Edited by Olof Hedman, 28 November 2012 - 08:08 AM.

### #3J. Evola's Apprentice  Members

307
Like
1Likes
Like

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)

Edited by teccubus, 28 November 2012 - 08:38 AM.

### #4hbdevelop1  Members

113
Like
0Likes
Like

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

### #5J. Evola's Apprentice  Members

307
Like
1Likes
Like

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.
http://floating-point-gui.de/

### #6hbdevelop1  Members

113
Like
0Likes
Like

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.