Sign in to follow this  
avion85

Rotation of vector by a quaternion

Recommended Posts

What is the best way to rotate a vector with a quaternion? As i see it, there is no dedicated way to do this within d3d(i use d3d9). There are a number of functions like: D3DXVec3Transform D3DXVec3TransformArray D3DXVec3TransformCoord D3DXVec3TransformCoordArray that transform a vector using a matrix, but none directly using a quaternion. So what is better to do, transform a quaternion to a matrix, and then use this matrix to transform my vector, or go "ground level" and do it myself like this:
vector rotate_with_quaternion(quaternion q, vector v)
  Quaternion t;
  t = q*v*(~q);   //~q is conjugate quaternion
return t.get_vector_component();

but then i need to define operators for vector-quaternion multiplication, and the whole thing gets complicated... What do you think? Maybe there is a third way? thanks

Share this post


Link to post
Share on other sites
If you want to transform more than one vector by a given quaternion then it's generally more efficient to transform the quaternion to a matrix and then transform all the vectors you want by that matrix.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this