#### Archived

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

# Angle-axis vector rotation + quaternions

This topic is 6041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I made a simple program where you can rotate around a space-ship like in descent and stuff using quaternions but now I have to figure out how to move forwards... how do I find the vector of which direction the ship is facing? I know how to convert quaternions into angle-axis rotation values but I don''t know how to turn any of them into a vector... Any help would be appreciated. -David-

##### Share on other sites

Assume that you know the ship is pointing in a direction such that it makes angles theta, phi and psi with your 3 ground based directional axes.

Then, your velocity vector is just:

V = speed*(cos(theta) i + cos(phi) j + cos(psi) k)

where theta is an angle relative to the i basis vector
phi is an angle relative to the j basis vector
psi is an angle relative to the k basis vector

Regards,

Tim

##### Share on other sites
If your quaternion is q and the ship''s forward direction is x (e.g. the x-axis), then just apply the quaternion to x to generate rotated x, i.e. the ship''s forward direction in it''s current rotated state. Mathematically that''s just

x'' = qxq''

where q'' = the conjugate as q and both x'' and x are treated as quaternions for this calculation.

##### Share on other sites
Timkin for that wouldn''t I need to have a euler rotation... I don''t know how to convert quaternions or angle-axis into euler.

Johnb sorry but I''m new to quaternions, do you know where I could find a piece of source code that could apply the quaternion to the vector?

##### Share on other sites
All you need to do is two quaternion products, i.e. first work out qx then multiply the result of this with q'' = the conjugate/inverse of q. Note that the it matters which order you multiply them.

How to multiply quaternions and much more is documented at http://www.gamasutra.com/features/19980703/quaternions_01.htm. There are a few other quaternions articles I''ve not had a look at on Gamedev''s Articles page.

##### Share on other sites
If you are using DX8 there is a bucket load of ''helper'' functions that convert back and forth from quats to axis angles and back again.

Just search for D3DXQuaternionToAxisAngle in the help.

D.V.

##### Share on other sites
How do I multiply a quaternion by a vector though... would the vector just be a quaternion with [0,x,y,z] instead of [x,y,z,w] or something?

-David-

AAAAARGH!