Archived

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

RamboBones

Quaternions

Recommended Posts

I''ve been having a couple of problems with quaternions. I''ve been learning them to make a camera class that works without gimble lock, the bane of euler rotations . Since when using quaternions to perform rotations the rotation you apply to the quat is done on the axis of the quat as it is. That works and I can get full 3D movement, however I''m wondering if there''s a way to use quaternions yet still somehow perform the rotations on it as aligned to the world axis. Anybody got some good ideas?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
FYI, your grammar isn''t bad, b/c I can understand what you''re talking about and I''ve just delved into quaternions using Tot3DGPGurus as an intro--and Lamothe sure knows how to dymistify quaternions. First thing you need to do is buy his book. It costs 59 dollars in the US but I got it for 58 with my B&N discount card (saves 10%, so ~3% when taxed), but you don''t care. You must get this for quaternions and every other mathematical mystery of 3D graphics. From his book, this is what you must do; and it''s called using the Euler angles to rotate with a quaternion:
Quaternion rotation:
v = vector to rotate, axis of rot and degrees is encoded in quaternion q
v'' = q * v * q~
where q~ is the conjugate of the quaternion q, that has a unit-normalized vector to rotate around. The conjugate, which when multiplied by q (order-independently) yields the sum of the squares of q''s real terms (which when taken the square root of gives q''s norm or magnitude), ["The conjugate..."] is nothing more than the negation of the vector part of q. If the axis encoded in q were not normalized, you''d have to use the inverse of q, instead of its conjugate, which is obtained by q^-1 = q~/(|q|^2). And note that the magnitude is also sqrt q*q~, so when q is itself normalized or of magnitude 1, q/|q| is one, and q^-1 essentially equals q''s conjugate. Get it? If you don''t, then buying Tricks of the 3D... is a must, because I myself would not have gotten what I just said before I read that enlightening section. To add: q~ * v * q (notice the order) is a rotation in the opposite of the clock direction that the first formula yields.
Continuing...
Well basically, you need to encode the three word axis rotations (x-y-z) into q. When can be accomplished with quaternion multiplication of 3 different "q''s", where in each one the corresponding vector component (either i,j,k where xyz are scalars to) must contain the formula, that was given in the book, for rotation. So... if q is incoded normally with an axis and you have an angle of rot to pass in called theta (t for short), you''d have:
q = cos(t/2)*q0 + sin(t/2)*qV //---the imaginary vector part of q with the reals: q1, q2, and q3, and the imaginary coefficients i-j-k
Thus you''d expand to:
q = cos(t/2)*q0 + [sin(t/2)*q1 * i,
sin(t/2)*q2 * j,
sin(t/2)*q3 * k]//that''s qV
and in explicit 4D vector form, that becomes:
(q0,q1,q2,q3) //but I''m too lazy to type the trig stuff, and in the book he had the vectors with alligartor brackets, but b/c HTML script, can''t use here, but they look much niser than parentheses
Continuin once more, to your question:
qX = cos(t/2) * [sin(t/2)*q1 * i, 0 * j, 0 * k]
qY = same thing but the sin thingy in the j component
qZ = same thing but the sin thingy in the k component
And the old formula of v'' = q~ * v * q becomes:
v'' = (qX * qY * qZ)~ * v * (qX * qY * qZ)
v, and v prime will be quaternions with q0 as 0, b/c they''re only 4D vectors so they can be implemented with quats (as in "4". Oh shit....Look back at the qX,qY,qZ quats where I had t for every angle...t would actually be different fo each axis. LOL. Go figure

-leinad (if you feel the need to flame me )

Share this post


Link to post
Share on other sites