How do I rotate a vector by a quaternion?
Printable View
How do I rotate a vector by a quaternion?
Kedaman posted something in Graphics I think... ;)
http://www.vbforums.com/showthread.p...6&goto=newpost
So what's 'quaternion', I haven't found it in my dictionary.
Perhaps I can help you.
It seems to be an axis in the first 3 elements, and the last is an angle to rotate around that axis (clockwise? anticlockwise? anyone know?)
A quaternion is a vector rotation angle.
The vector part is the axis about which the vertices are rotated.
The angle uses the right hand rule for rotation. You point your right hand thumb in the direction of the vector and your fingers curl in the positive angle direction
Common Quaternions
x axis D3DXQUATERNION ( 1, 0, 0, ANGLE)
y axis D3DXQUATERNION ( 0, 1, 0, ANGLE)
z axis D3DXQUATERNION ( 0, 0, 1, ANGLE)
They are very usfeul for smooth movement of objects. Using a linear intepolation function you can move smoothy from one angle and rotation to another.
I'll ask my question now as well ;)
How do you concatenate two quaternions? (as in, you have two rotations and you want a single rotation to express that) Or isn't it possible?
I think to concatenate 2 quaternions, you will just have to handle with the angles as if they are vectors, and then you add one to the other.
nah, you don't treat quaternions as vectors, to combine rotations you do quaternion multiplication
Q1 X Q2 = ( w1·w2 - v1·v2, w1·v2 + w2·v1 + v1xv2 )
· is dot product and x is crossproduct
the components w,x,y and z where:
Q1 = w1 + x1*i + y1*j + z1*k
Q2 = w2 + x2*i + y2*j + z2*k
i,j and k are the unit quaternions
and the vectors v1 and v2 are:
v1 = (x1, y1, z1)
v2 = (x2, y2, z2)
simplified:
Q1 X Q2 = (w1*w2 - x1*x2 - y1*y2 - z1*z2) + (w1*x2 + x1*w2 + y1*z2 - z1*y2)*i + (w1*y2 + y1*w2 + z1*x2 - x1*z2)*j + (w1*z2 + z1*w2 + x1*y2 - y1*x2)*k
quaternion multiplication is not commutative :p
Is it associative? :p
i guess it is (i'm not sure, never tested) as long as they are in the correct order.