PDA

View Full Version : Question about quarternion rotation



jenny_wui
07-07-2010, 05:27 AM
I have some question about quarternion rotation. Suppose when I rotate the object, each time I get the angle in quarternion axis-angle form. Now I want the object back to its initial position. How can I add up all the quarternion angle-axis? Because I need to add up all the angular rotation and then rotate the current object to the negative of that angle to come back to the initial position. Any suggestion will be highly appreciated.

Rosario Leonardi
07-07-2010, 05:59 AM
To combine the rotation of two quaternions just multiply them.

object.rotate(A);
object.rotate(B);
object.rotate(C);
object.rotate(D);

totalRotation = A * B * C * D;

// restore the original orientation
object.rotate(totalRotation.inverse());

I don't suggest this approach cause is error prone, combining a lot of rotation can lead to floating point approximation error.

a better approach is

originalRotation = object.getRotation();

object.rotate(A);
object.rotate(B);
object.rotate(C);

//restor the rotation
object.setRotation(originalRotation);

strattonbrazil
07-07-2010, 08:21 AM
I could be wrong here, but isn't

object.rotate(A);
object.rotate(B);
object.rotate(C);
object.rotate(D);

actually

totalRotation = D * C * B * A;

?

Rosario Leonardi
07-07-2010, 12:58 PM
mmm... mumble...
P.rotated(qa) ==> P' = qa * P * qa(-1)

P.rotated(qa)
P.rotated(qb)
==
P" = qb * (qa * P * qa(-1)) * qb(-1) ==
(qb * qa) * P * (qa(-1)*qb(-1)) ==
(qb * qa) * P * (qb*qa)(-1)
==
P.rotated(qb*qa)

ups.. you are right. :D

jenny_wui
07-08-2010, 05:09 AM
Thank you very much for your reply. It helped a lot in understanding the thing.