Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Quaternions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 kumpaka   Members   -  Reputation: 100

Like
0Likes
Like

Posted 29 March 2012 - 11:48 AM

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.

Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 13933

Like
1Likes
Like

Posted 29 March 2012 - 01:36 PM

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.

#3 kumpaka   Members   -  Reputation: 100

Like
0Likes
Like

Posted 29 March 2012 - 02:20 PM

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)

#4 Álvaro   Crossbones+   -  Reputation: 13933

Like
0Likes
Like

Posted 29 March 2012 - 02:56 PM

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.

#5 kumpaka   Members   -  Reputation: 100

Like
0Likes
Like

Posted 29 March 2012 - 07:20 PM

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?

#6 Álvaro   Crossbones+   -  Reputation: 13933

Like
1Likes
Like

Posted 29 March 2012 - 09:42 PM

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

#7 kumpaka   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 March 2012 - 10:52 AM

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.

#8 Álvaro   Crossbones+   -  Reputation: 13933

Like
1Likes
Like

Posted 30 March 2012 - 11:16 AM

No, the vector you are rotating can have any length.

#9 kumpaka   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 March 2012 - 11:49 AM

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));
}


#10 Álvaro   Crossbones+   -  Reputation: 13933

Like
1Likes
Like

Posted 30 March 2012 - 12:20 PM

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.

#11 kumpaka   Members   -  Reputation: 100

Like
0Likes
Like

Posted 30 March 2012 - 12:53 PM

Ok then i got this sorted, ty very much for your help.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS