Axis angle to Vector

Started by
15 comments, last by Nanook 14 years, 5 months ago
I got an angle axis from a quoternion for an object in my game and need to find the direction vector for where the object is facing.. how can I find this?
Advertisement
A quaternion represents a rotation about an axis angle, not an absolute direction. So, you can't find the direction the object is currently facing unless you know the original direction it faced.

If you know the original direction:
- create a 3x3 rotation matrix from the quaternion
- multiply the original direction of the object by the matrix

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Why would you go through the 3x3 matrix? Just take the original direction and rotate it using the quaternion normally (i.e., by conjugation).

Im still not sure how to do this? When my game starts the original orientation would be the same as the current orientation wouldn't it?
Quote:When my game starts the original orientation would be the same as the current orientation wouldn't it?

Yes, before any changes are made. At that point, you should know which direction your object is facing. That's the direction you would use for the calc later.

Perhaps if you're a bit more specific about what language you're programming in, what the "object" is, etc., you can get more specific help.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

My problem is that I need to add an acceleration force to my spaceship so I need to know where its facing.. so I need to get the orientation vector so I can multiply that with my acceleration force.. Im using c++

I just started using quaternions so I need a good explenation..

I guess the original orientation is 0,0,-1 as I'm using opengl.. I've set it up so everytime a new orientation quaternion is set I multiply it by the previous orientation vector, but this doesn't seem to give me the right vector..

orientationDir is the vector (set to 0,0,-1 at startup) and orientation is the quaternion:

orientationDir = orientation * orientationDir;
orientationDir.normalize();
I guess you just don't know how to apply to a vector a rotation specified by certain quaternion. You should probably read and understand the Wikipedia page about quaternions and rotation. Basicaly you need to multiply
rotated_vector = quaternion * original_vector * inverse(quaternion)

This operation is called "conjugation". Since the quaternion in question is a unit quaternion, you can compute its inverse just by flipping the sign of the three imaginary coefficients.

Yeah I know I'm running out of time for this project right now though, but I will use time during my break to read on quaternions.. We're abit ahead with quaternions, we didn't realy need to use them.. so I just need to get this working now..

but does it matter what order I multiply them? Is this supposed to work?

orientationDir = orientation * orientation.inverse() * orientationDir;
Yes, order matters. Multiplication of quaternions is not commutative.
Quote:everytime a new orientation quaternion is set I multiply it by the previous orientation vector

Is the "new" orientation quat the total orientation of the object, or a change in orientation?

If it's the total orientation, then don't multiply it by the previous orientation.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement