Hello there, I want to multipy two quaternions as to rotate them.

I read http://www.songho.ca/math/quaternion/quaternion.html and found the formula for a length preserving rotation:

p * q * conj(p)

and tried to use this in my program.

however the magnitude of this result is not 1, while |p| and |q| are both 1.

What's going on? does this formula only work for preserving the vector part? And if so what is the proper way to multiply two quaternions represting rotations?

here is my multiplication function:

quaternion operator*( const quaternion& a, const quaternion& b ) { vec3 c = vecpart(a); vec3 d = vecpart(b); return quaternion( cross( c, d ) + (a.w * c) + (b.w * d), a.w*b.w - dot( c, d )); }

and conj(q) = [scalar(q), -vector(q)]

thanks!