View Full Version : Quaternion

piercec

04-19-2002, 12:41 AM

The quaternions that represent rotated 0 degree and 360 degrees about x should be the same or not.

My quaternio representing rotated 0 is (w,x,y,z) = (1.0,0.0,0.0,0.0);

and quaternion representing rotated 360 is

(w,x,y,z) = (-1.0,0.0,0.0,0.0);

Is that right?

Thanks.

zeckensack

04-19-2002, 12:52 AM

Originally posted by piercec:

Is that right?

Yup, that's right http://www.opengl.org/discussion_boards/ubb/smile.gif

Gavin

04-19-2002, 12:57 AM

No that is wrong. you are rotating +/- 1 degree about no axis!

piercec

04-19-2002, 01:02 AM

Originally posted by zeckensack:

Yup, that's right http://www.opengl.org/discussion_boards/ubb/smile.gif

Doesn't quaternion mean "orientation"?

If their orientations are the same, why aren't their quaternion?

And if I want to make a object turn 360 degrees, the 6 keyframes saving quaternions with rotation 0, 90, 180, 270, 360, 0 will success or not. I mean would there be any problem in interpolation between 360 ad 0.

Thanks.

piercec

04-19-2002, 01:12 AM

Originally posted by Gavin:

No that is wrong. you are rotating +/- 1 degree about no axis!

If I want to rotate an object about x axis,

I will convert the rotation to quaternion and multiply the quaternion with the current quaternion to get a new quaternion.

Quaternion AxisAngleToQuaternion(int degree,float X, float Y, float Z)

{

Quaternion result;

float angle = float((-degree / 180.0f) * 3.14159265);

float buff = (float)sin( angle / 2.0f );

result.w = (float)cos( angle / 2.0f );

result.x = float(X * buff);

result.y = float(Y * buff);

result.z = float(Z * buff);

return result;

}

Quaternion QRotate(tJoint joint)

{

Quaternion result = initQuaternion();

Quaternion buff = initQuaternion();

result = AxisAngleToQuaternion(joint.rot.x,1.0,0.0,0.0);

buff = AxisAngleToQuaternion(joint.rot.y,0.0,1.0,0.0);

result = myMultiQ(buff,result);

buff = AxisAngleToQuaternion(joint.rot.z,0.0,0.0,1.0);

result = myMultiQ(buff,result);

return result;

}

Quaternion myMultiQ(Quaternion q1, Quaternion q2) // multiplication of two quaternions

{

Quaternion result;

result.w = q1.w*q2.w - q1.x*q2.x - q1.y*q2.y - q1.z*q2.z;

result.x = q1.w*q2.x + q1.x*q2.w + q1.y*q2.z - q1.z*q2.y;

result.y = q1.w*q2.y - q1.x*q2.z + q1.y*q2.w + q1.z*q2.x;

result.z = q1.w*q2.z + q1.x*q2.y - q1.y*q2.x + q1.z*q2.w;

return result;

}

anything above wrong??

I've been working in quaternion for days.

Thank you.

Gavin

04-19-2002, 03:01 AM

Originally posted by Gavin:

No that is wrong. you are rotating +/- 1 degree about no axis!

I think you just typed it wrong...

(w,x,y,z) = (-1.0,0.0,0.0,0.0);

this is rotating -1 (w) degrees about the axis

(0, 0, 0).

The quaternians are the same, really. You are rotating by 0/360 degrees so the axis could be anything and you would always end up where you started.

Gavin

04-19-2002, 03:05 AM

There is some quat code at www.cs.cf.ac.uk/user/G.R.Powell (http://www.cs.cf.ac.uk/user/G.R.Powell)

->C Code

zeckensack

04-19-2002, 03:17 AM

Originally posted by Gavin:

Originally posted by Gavin:

No that is wrong. you are rotating +/- 1 degree about no axis!No.

I think you just typed it wrong...

(w,x,y,z) = (-1.0,0.0,0.0,0.0);

this is rotating -1 (w) degrees about the axis

(0, 0, 0).

Here's your mistake: the w value is the cosine of half the rotation angle. It's perfectly valid this way, the cosine of 360/2=180 degrees is -1.

This may or may not cause problems while slerping but nevertheless it is a perfectly valid unit quaternion.

zeckensack

04-19-2002, 03:36 AM

Originally posted by piercec:

Doesn't quaternion mean "orientation"?

If their orientations are the same, why aren't their quaternion?Well, that's a bit over my head. Complex number stuff I guess. If you had two rotations, by 0° and by 720°, these would yield the same quats.

And if I want to make a object turn 360 degrees, the 6 keyframes saving quaternions with rotation 0, 90, 180, 270, 360, 0 will success or not. I mean would there be any problem in interpolation between 360 ad 0.Huge problem with a 360° turn between keyframes. Because of the normalization constraint (w*w+x*x+y*y+z*z==1) you don't have any axis information. IE w will be 1.0 in a 360° rotation, so you can't represent an axis at the same time, x y z will all be zero. So you just can't do that with a quaternion.

Of course you need an axis for an interpolated 360° turn. A simple way around this would be to split the animation, say, into two 180° turns.

If you do it in smaller steps anyway, you're safe http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by zeckensack (edited 04-19-2002).]

[This message has been edited by zeckensack (edited 04-19-2002).]

Gavin

04-19-2002, 05:51 AM

Yeah, fine but..... what I was on about is that his x, y, z are 0. As you know this is the axis of rotation. This should be a unit vector.

zeckensack

04-19-2002, 07:44 AM

Originally posted by Gavin:

Yeah, fine but..... what I was on about is that his x, y, z are 0. As you know this is the axis of rotation. This should be a unit vector.

Right, no axis information. There can't be any. In a unit quat (the only type of quat useful for representing orientation stuff), the (x y z) part is not a unit vector, the hole thing is normalized. (well, in the specialty case when w==0 it is a unit vector, but most of the time it's not)

If w==1 then (x y z)==(0 0 0). That's a problem, I agree. But not a problem in piercec's code, rather a problem with quats in general.

I only wanted to point out that w is not a rotational angle http://www.opengl.org/discussion_boards/ubb/wink.gif

piercec

04-19-2002, 09:57 AM

Thank you, zeckensack and Gavin.

I thought 0 and 360 degree rotation as the same things.

I have solved my problem.

Thanks for all of your help.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.