#### Archived

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

# Quaternion Questions

## Recommended Posts

Just a couple questions on Quaternions for rotations; Just to note, i''m assuming OpenGL stuff, since that''s what i learnt Let''s say that i''m starting with a camera at the origin, with the vUp vector as (0,1,0). If i want to rotate, say, 10 degrees (converted into radians) to the right, i would take the current axis and rotation i''m at (which i''m assuming would be zero) and then form the quaternion for the resulting rotation, and multiply them together? THis is a very simple example, but i guess i can generalize it, so lets say i''m arbitrarily positioned in space, and want to rotate to the right, i just take the current quaternion and multiply that by the resultant quaternion, and that''s what i''d be using to input the glRotate values? Thanks a lot in advance!

##### Share on other sites
heres a synopsis of how i do quaternian rotation. bear with me as it''s been a while, my quaterion is setup w/ s and a vertex as internals.

find the sine of your rotation angle. Mult y of vUp by that, set that to quaternion1''s vector

set the s member of quaternion1 to the cos of the angle.

set quaternion2''s s to the cos of the angle also.

set quaternion2''s vector vUp * -(sine of angle)

setup quaternion3 to s =1 and the vertex = the vertex to rotate

quaternion4 = quaternion1 * quaternion3 * quaternion2

the rotated vertex is now the vertex segment of quaternion4, do with it what you will.

you can internalize all this into your quaternion setup, this is just a rundown of how i have it setup

##### Share on other sites
"Let''s say that i''m starting with a camera at the origin, with the vUp vector as (0,1,0). If i want to rotate, say, 10 degrees (converted into radians) to the right, i would take the current axis and rotation i''m at (which i''m assuming would be zero) and then form the quaternion for the resulting rotation, and multiply them together?"

This is more or less correct.

Somewhere in your quaternion class you''ll want a function that takes an axis/angle representation and converts it to quaternion form. The conversion goes like this:

q.x = sin(angle / 2)axis.x
q.y = sin(angle / 2)axis.y
q.z = sin(angle / 2)axis.z
q.w = cos(angle / 2)

You''ll start with a unit quaternion that represents your initial orientation. To rotate 10 degrees to the right, you would create a new quaternion with axis 0, 1, 0 and angle 10 degrees, and multiply it by your original quaternion. The resulting quaternion is your new orientation.

Keep in mind that to rotate left or right, you have to rotate around the object''s up vector. As long as you only yaw, this will remain 0, 1, 0. But once you pitch or roll your local up vector will change.

There are functions to convert a quaternion to a matrix, and your up vector (as well as your side and forward vectors) can be extracted from this matrix.

• ### Forum Statistics

• Total Topics
628320
• Total Posts
2982072

• 21
• 9
• 9
• 13
• 11