# Angle-axis vector rotation + quaternions

Started by David20321, Jul 04 2001 06:18 PM

8 replies to this topic

###
#1
Members - Reputation: **122**

Posted 04 July 2001 - 06:18 PM

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-

Sponsor:

###
#2
Members - Reputation: **864**

Posted 04 July 2001 - 08:16 PM

Your vector is already contained in the information you have.

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

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

###
#3
Members - Reputation: **351**

Posted 04 July 2001 - 08:54 PM

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.

x'' = qxq''

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

###
#4
Members - Reputation: **122**

Posted 05 July 2001 - 06:56 AM

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?

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?

###
#5
Members - Reputation: **351**

Posted 05 July 2001 - 09:26 PM

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.

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.