Sign in to follow this  

Quaternions

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

If you intended to correct an error in the post then please contact us.

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?

Thanks in advance.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
[quote name='kumpaka' timestamp='1333070446' post='4926510']
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?
[/quote]
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 this post


Link to post
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 this post


Link to post
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: [url="http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Rotating_vectors"]http://content.gpwiki.org/index.php/OpenGL:Tutorials:Using_Quaternions_to_represent_rotation#Rotating_vectors[/url]

They actually normalize the vector they are about to rotate:

[CODE]
// 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));
}
[/CODE]

Share this post


Link to post
Share on other sites
[quote name='kumpaka' timestamp='1333129744' post='4926738']
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
[/quote]

That's just wrong. Ignore it.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this