• 12
• 11
• 9
• 10
• 13

# Quaternions

This topic is 2182 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there,

So I've been working around with quaternions, let me just see if i got this straight:

v' = q . v. q^-1

Will get me a new vector with an applied rotation?
To do this multiplication we turn v into a quaternion by adding scale with value 0, and from the resulting quat. we can extract the vector value to get the result. But on this new resulting quat, for us to just simply extract the values doesnt the scale of the resulting quaternion need to be 0? Or whatever the value is, we just dont mind and extract the vector values anyways?

##### Share on other sites
While your formula is correct, you can simply compute

v' = q * v * conj(q)

because, for quaternions that represent rotations, |q| = 1.

I am not sure what you mean by the "scale" of a quaternion. v' as a quaternion has zero real part, if that's what you mean. Proving that theorem shouldn't be too hard. So just don't worry about it and extract your vector.

##### Share on other sites
I started to prove that today on paper(yeah by scalar i meant real part, on book im reading he calls it scalar, on some toturials it's the 'w') and thats what i got, it should be zero i was just afraid i did the math wrong. The examples i try on my code dont end up getting 0 on the real part, means im doing something wrong... need to find out what and correct it, just wanted to be sure i was on the right path.

Btw, you say for quaternions that represent rotations |q| = 1, i calculated it, for example with this:
alpha = 90º
v = (1.0,0.0,0.0)
q = [cos(90/2), sin(90/2) * (v)]
But it did not result in a normalized quaternion, again the math on my code must be working improperly right?

Thank you.

PS(before calculating the cos or sin, i convert de degree's to radians)

##### Share on other sites
Remember that v needs to have lenght 1 for that code to work. If it does, |q| = 1 is guaranteed. If you don't think this is the case, please post a complete example so we can discuss it.

EDIT: Oh, sorry. You did post a complete example. Well, perhaps you can post why you think the resulting quaternion is not normalized.

##### Share on other sites
Its solved, the math i had on paper was right but not the one on code =( both problems were solved, my vector dot product and vector cross product had mistakes. Thank you.

PS: If the vector i want to rotate does not have lenght 1, i need to normalize it? Rotation quaternions, if calculated by that formula are always unit quaternions?

##### Share on other sites

PS: If the vector i want to rotate does not have lenght 1, i need to normalize it? Rotation quaternions, if calculated by that formula are always unit quaternions?

Yes, if the vector that indicates the axis doesn't have length 1, you need to normalize it. Once you have a vector of length 1, the length of the resulting quaternion is

length(q) = length(cos(alpha/2) + sin(alpha/2)*x*i + sin(alpha/2)*y*j + sin(alpha/2)*z*k) = cos(alpha/2)^2 + sin(alpha/2)^2*(x^2+y^2+z^2) = cos(alpha/2)^2 + sin(alpha/2)^2 = 1

##### Share on other sites
I see, that was very helpful indeed thank you.

What about the vector i want to rotate? on v' = q . v . conj(q), does 'v' also need to be normalized? Because if it does, wont it alter the result intended?

Very sorry if this sound like dumb questions, just started looking at quaternions a few days ago =( You're help is much appreciated.

##### Share on other sites
No, the vector you are rotating can have any length.

##### Share on other sites
This is making me confused, i tought and it made sense. I was happy i got this out of the way, but now i found this here: http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Rotating_vectors

They actually normalize the vector they are about to rotate:

 // Multiplying a quaternion q with a vector v applies the q-rotation to v Vector3 Quaternion::operator* (const Vector3 &vec) const { Vector3 vn(vec); vn.normalise(); Quaternion vecQuat, resQuat; vecQuat.x = vn.x; vecQuat.y = vn.y; vecQuat.z = vn.z; vecQuat.w = 0.0f; resQuat = vecQuat * getConjugate(); resQuat = *this * resQuat; return (Vector3(resQuat.x, resQuat.y, resQuat.z)); } 

##### Share on other sites

This is making me confused, i tought and it made sense. I was happy i got this out of the way, but now i found this here: http://content.gpwik...otating_vectors

That's just wrong. Ignore it.