# 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 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.