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.

To combine the rotation of two quaternions just multiply them.

object.rotate(A);
object.rotate(B);
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);

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

I could be wrong here, but isn’t

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

actually

totalRotation = D * C * B * A;

?

mmm… mumble…
P.rotated(qa) ==> P’ = qa * P * qa(-1)

# P" = qb * (qa * P * qa(-1)) * qb(-1) == (qb * qa) * P * (qa(-1)qb(-1)) == (qb * qa) * P * (qbqa)(-1)

P.rotated(qb*qa)

ups… you are right. Thank you very much for your reply. It helped a lot in understanding the thing.