**0**

###
#1
Members - Reputation: **100**

Posted 29 March 2012 - 11:48 AM

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.

###
#2
Crossbones+ - Reputation: **16573**

Posted 29 March 2012 - 01:36 PM

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
Members - Reputation: **100**

Posted 29 March 2012 - 02:20 PM

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
Crossbones+ - Reputation: **16573**

Posted 29 March 2012 - 02:56 PM

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

###
#5
Members - Reputation: **100**

Posted 29 March 2012 - 07:20 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?

###
#6
Crossbones+ - Reputation: **16573**

Posted 29 March 2012 - 09:42 PM

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 isPS: 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?

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
Members - Reputation: **100**

Posted 30 March 2012 - 10:52 AM

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.

###
#9
Members - Reputation: **100**

Posted 30 March 2012 - 11:49 AM

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
Crossbones+ - Reputation: **16573**

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.