calculate quaternion using cos and sin

Get answers to all your basic programming questions. No Ogre questions, please!
rimie23
Greenskin
Posts: 131
Joined: Sun Apr 22, 2012 1:55 pm

calculate quaternion using cos and sin

Post by rimie23 »

hi
is there methode to calculate angle or quaternion using sin and cos?
because i have note the angle but i have the cos and the sin
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 535

Re: calculate quaternion using cos and sin

Post by Kojack »

The formula for a quaternion is:
w = cos(angle/2)
x = axis.x * sin(angle/2)
y = axis.y * sin(angle/2)
z = axis.z * sin(angle/2)

But as you can see there you need the cos and sin of half the angle. If you have cos and sin of the whole angle, it won't work directly (need to get back to the angle so you can halve it).
User avatar
Daixiwen
Greenskin
Posts: 105
Joined: Fri Feb 08, 2013 11:30 am
Location: Oslo
x 16

Re: calculate quaternion using cos and sin

Post by Daixiwen »

Or you could use the fact that cos(angle) = 2 * cos(angle/2)^2 - 1 = 1 - 2 * sin(angle/2)^2 , but I'm not sure it would be more efficient than using acos to recover the angle and then cos and sin again.
rimie23
Greenskin
Posts: 131
Joined: Sun Apr 22, 2012 1:55 pm

Re: calculate quaternion using cos and sin

Post by rimie23 »

thanks