Calculating vector from quaternion

Started by
5 comments, last by Megaboz 18 years, 3 months ago
Hello - I'm currently using a quaternion, converted to an axis-angle, for rotations. This is probably an easy question, but using that quaternion, how can I calculate a 3d vector of the direction it's pointing? I don't fully understand quaternions, but I know everything I've read says the vector component of it cannot be treated as a regular 3D vector, so I'm assuming I can't just extract from that, I assume I need to apply some trigonometric functions first. Thanks for any help you can give!
Advertisement
Just transform the original facing vector by the quaternion. Quaternions represent rotations.
So would I first convert my quaternion into a rotation matrix, and then multiply my original vector by that rotation matrix, the resulting matrix containing my new vector? Or am I totally off? I'm still a little fuzzy with the math.
You don't need to turn a quaternion into a matrix in order to apply a quaternion rotation to a vector. vrotated = q * voriginal * q-1

Also a vector multiplied by a matrix should give a vector not a matrix.
Sorry, I meant a single column matrix representing the vector, not a full 4x4 or 3x3 or whatever.

I'm confused though about what you're saying - maybe if I gave more info about what I'm doing you could clear up the parts I'm misunderstanding -

I'm representing my camera as a quaternion, which I implement as a class with 4 floats (w,x,y,z), some functions to normalize, multiply, convert to an axis-angle, etc.

I have the rotations working great, after multiplying the original quat by the temp quat, I take the axis-angle of the new quaternion, and send that to a glRotate.

So now let's say that I wanted to move the camera forward 1 unit in the Z direction - but I'm keeping track of world coordinates, so I don't just want to directly call a glTranslate, I want to know the translated coordinates. I know the relative vector of which way I want to go (1 unit in the z), I know my camera's current rotation via its quaternion, and I know the camera's current world coordinates - what series of calculations would I use to determine the camera's new coordinates?

I'm assuming that once I know the vector of what direction I'm facing I can simply multiply each component by the magnitude, so that part's easy, I'm just not sure about actually getting that vector from my camera's rotation quaternion.
Assuming you wanted your camera's rotation to be applied to the translation, you would transform the vector of translation by the camera's rotation quaternion. So it sounds like you would transfrom (0, 0, 1) by some quaternion q. This can be done by either transforming the quaternion into a matrix and then using that matrix to transform the translation vector. However, you can also skip the transformation of the quaternion into a rotation matrix by directly transforming the translation vector by the quaternion. The equation for that is vrotates = q * voriginal * q-1.
Quote:Original post by SiCrane
Assuming you wanted your camera's rotation to be applied to the translation, you would transform the vector of translation by the camera's rotation quaternion. So it sounds like you would transfrom (0, 0, 1) by some quaternion q. This can be done by either transforming the quaternion into a matrix and then using that matrix to transform the translation vector. However, you can also skip the transformation of the quaternion into a rotation matrix by directly transforming the translation vector by the quaternion. The equation for that is vrotates = q * voriginal * q-1.


Thanks for your responses, I managed to get it working with your help, it wasn't quite clear in my head until now. Thanks again!

This topic is closed to new replies.

Advertisement