View Full Version : Rotating 3D Vectors by Quaternions
Wahooney 04112005, 09:11 AM Hey guys,
Can anyone tell me exactly how you rotate a 3D vector by a quaternion?
I know it's something like:
v1 = qr * v * (inverse qr)
But how the hell do you multiply a 4D quaternion and a 3D vector?!?
Thanks in advance.


playmesumch00ns
04112005, 10:39 AM
You don't. Quaternions are just a useful intermediary way of storing/updating the rotation. To actually perform that rotation on a 3space you'll need to construct a transformation matrix from the quaternion, then apply that matrix to your vector.
This page (http://www.gamedev.net/reference/articles/article1095.asp) contains some good info on quaternions and their representation in 3D.
Wahooney
04112005, 10:42 AM
But at the end of this (http://www.gamedev.net/reference/articles/article1691.asp) article (http://www.gamedev.net/reference/articles/article1691.asp) they say it is possible.
mbaas
04112005, 12:34 PM
Before multiplying you have to "convert" the vector into a quaternion which is simply done by setting the imaginary part (x,y,z) to your vector and the real part w to 0.
See also http://mathworld.wolfram.com/Quaternion.html (equation 30).
 Matthias 
craigd
04112005, 02:21 PM
You treat the vector you want to rotate as a quaternion with the scalar part 0.
#include <ImathVec.h>
#include <ImathQuat.h>
// rotate v by q
template <class T>
inline Imath::Vec3<T> rotate(const Imath::Vec3<T> &v, const Imath::Quat<T> &q) {
return (q*Imath::Quat<T>((T)0.0,v)*q.inverse()).v;
}
Wahooney
04112005, 02:41 PM
Thanks craigd. :thumbsup:
CGTalk Moderation
04112005, 02:41 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©20002015, Jelsoft Enterprises Ltd.