#### Archived

This topic is now archived and is closed to further replies.

# Quaternions(again)

This topic is 5961 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

From looking at the forum I''m sure everyones sick of quaternions, but my question is simple: if quaternions are used to "represent a transformation" such as rotation in the form of 4 numbers w,x,y,z then how do I set these values for a transformation (or alter them) and then how do I use these values to do the transformations (I only need to end up with an angle and a vector for the opengl rotatef function.) I dont intend to understand how they actually work, at the moment, just to resolve my frustration about my failing 3d program. The "why"s and "how"s of it will be resolved some day, but can somone just answer these hopefully more straight forward questions. The help really will be appreciated, thanks.

##### Share on other sites
axis (X,Y,Z) angle (A) to quaternion (w,x,y,z) :

normalize (X,Y,Z) (X^2+Y^2+Z^2==1)
w = cos(A/2)
(x,y,z) = (X,Y,Z)*sin(A/2)

quaternion to axis/angle
A = 2*acos(w)
(X,Y,Z) = (x,y,z)/sqrt(1-w^2) // irrelevant if A == 0

quaternion to transformation matrix (will be faster than glRotate, use glMatrixMultiply). You might need to use the transposed of the following matrix though (element ordering...)
| 1-2yy-2zz   2xy+2wz   2xz-2wy 0 ||   2xy-2wz 1-2xx-2zz   2yz+2wx 0 ||   2xz+2wy   2yz-2wx 1-2xx-2yy 0 ||      0         0         0    1 |[code]Edited by - Fruny on February 25, 2002 5:41:13 PM

##### Share on other sites
Thank you so much. I''ve been looking for that answer for quite a while, that''s just I wanted. Thanx again.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 20
• 12
• 11
• 41
• ### Forum Statistics

• Total Topics
631401
• Total Posts
2999869
×