Rotate a Vector by a Quaternion?

Miscellaneous Forums/General Discussion/Rotate a Vector by a Quaternion?

Would anyone have code or a simple explanation on the process to rotate a vector by a quaternion?

I've tried Chroma's code here ( http://www.blitzbasic.com/codearcs/codearcs.php?code=1550 ) but it returns a quaternion and I'm expecting that a rotated vector should be a vector. Also, if I ignore the n (n? w, surely? ) component and just use the x,y and z, it doesn't give me the expected result. Unless I misread it anyway.

I also tried the explanation here ( http://www.sacredsoftware.net/tutorials/Quaternions/Quaternions.xhtml ) but although it's a beautifully simple explanation, it's virtually impossible to follow when debugging because it asks you to start by creating a quaternion value which is invalid. So I can't possibly imagine what's going to happen when I start doing math with that invalid quaternion. And if I don't know what the value should be, I can't hope to spot where I've gone wrong.

Why don't you use the:

' Purpose: Gets the XYZ Component of a Quaternion



after using the multiply method on the quat? Is that what you were doing ... looking at it quickly I'm guessing it extracts the vector out of the encoding and doesn't just drop the w component of the quat.

Convert the vectors orientation to a quaternion, SLERP it, convert it back?