# Thread: Rotating a point using a quaternion, then using an inverse quaternion to rotate back?

1. ## Rotating a point using a quaternion, then using an inverse quaternion to rotate back?

I have a function that takes a unit quaternion <w,x,y,z> and a point <x,y,z> and spits out the rotated 3d point.
void rotate(const float *quaternion, const float *point, float *newpoint)

This code works OK:
void rotate(quaternion, point, newpoint)

I would now like to rotate the point back to where it was originally. I understand this is possible using the inverse of the quaternion (which for a unit quaternion is equivalent to the conjugate, right?):

This is how I do this this:
inverse_quaternion;
inverse_quaternion = quaternion; //w
inverse_quaternion = -quaternion; //x
inverse_quaternion = -quaternion; //y
inverse_quaternion = -quaternion; //z
void rotate(inverse_quaternion, rotated_point, final3dpoint)

Unfortunately this is not doing what I expect. What am I missing? 2. What you have will only work if the quaternion is normalized, otherwise you've got to multiply by 1/[magnitude squared] (or 1/[Q dot Q]):
Code:
```float dot = quaternion*quaternion + quaternion*quaternion + quaternion*quaternion + quaternion*quaternion;
inverse_quaternion = quaternion / dot; //w
inverse_quaternion = -quaternion / dot; //x
inverse_quaternion = -quaternion / dot; //y
inverse_quaternion = -quaternion / dot; //z```
And if this isn't the problem, could you post your code for rotate()? It can be hard to catch mistakes in all the similar-looking arithmetic involved in this sort of stuff. 3. Ok, I modified my multiplication code and now it works out (sans some small math errors. Hmm, guess I better figure out what's going on there! When mapped, the z and y axis are correct, but the x axis appears to be inversed.  4. Originally Posted by fuse Ok, I modified my multiplication code and now it works out (sans some small math errors. Hmm, guess I better figure out what's going on there! When mapped, the z and y axis are correct, but the x axis appears to be inversed. This sounds like a problem with your world matrix or the way you are constructing it from the up, right, and look vectors. Popular pages Recent additions 