Sign in to follow this  

concatenating rotation around different origins

Recommended Posts

Hi everybody, Im going mad with a problem I have in developing an application that lets the user rotate a simple object around a specific origin.. the rotations are only about the Y and X axis.. the problem is that the origin of rotation can change. now, everything is ok until I change the rotation origin.. it seems like the first rotation changes the axis for the subsequent rotations example: rotate 47deg around Y rotate 23deg around X and everything is fine.. then I change the rotation origin and when I, say, rotate 20deg around X, the X axis the object will rotate is not anymore world-X. Im using matrices, and multiply the new rotation mat everytime the origin changes. I switched to quaternions, and got exactly the same results I had with matrices. Is there something Im missing? Thank you :)

Share this post

Link to post
Share on other sites
Assume that an object is transformed by a matrix M so far. An additional rotation R applied about a world axis gives then
R * M
(using column vectors; change the order if you're using row vectors). If you want to use another center of rotation, then you have to make the desired center temporarily the origin, i.e. you define another "rotation"
R' := T * R * T-1
where T denotes the translation matrix to the desired center of rotation. Substition gives then
T * R * T-1 * M

Share this post

Link to post
Share on other sites
sorry I was in a bit of a hurry while writin my last post..

of course, in order to define a new center of rotation, opportune translations take place..

the actual code is something like this:


m is a matrix converted from the rotation quaternion

there is a main matrix k, which gets modified by each translation and rotation, and is reset before each loop, unless there is an origin change, in which case it is multiplied by the new translation/rotation/translation matrix and so forth..

I can rotate and translate everything for as long as I want, and everything is ok (k -identity at the beginning- is calculated at each loop).

but when I chancge the origin, I get a new x,y,z, reset rotation angles, recalulate m. k (which holds t/r/t around the last origin) is saved and reloaded at each loop, so that the new transformations (t/r/t) add up to the last-origin k.

I have to multiply matrices when changing origin, otherwise the rotations will be ok, but the object will suddently change screen position while rendering (the new origin will be in the middle of the screen).

the problem is that the new rotations will not refer to the world axis anymore.

hope Ivenot been too messy :)

Share this post

Link to post
Share on other sites
Err, well, I'm sure that I haven't understood ;(

Mathematically the precedence is clear: When using column vectors, then the sequence
R1 * v
means that v is rotated about the global axis as incorporated in R1.

Multiplying another rotation on the left (remember: column vectors) ever means to do another rotaton about a global axis.
R2 * R1 * v
i.e. v is rotated about the global axis as incorporated in R1, and the result of that is rotated about the global axis as incorporated in R2. There is no possibility that a translation changes this.

If you accidentally do a multiplication on the right
R1 * R2 * v
then the effect is that you seem to rotate about a local axis.

This is because after the first rotation
you may create a rotation
R2' := R? * R2 * R?-1
so that the desired local axis becomes temporarily the global one (this is equivalent to the temporary center of rotation concept). Now, since R1 defines the current orientation, it is clear that
R? == R1
must hold. Hence after substitution we get
R1 * R2 * R1-1 * R1
= R1 * R2

For row vectors you have to reverse all the matrix products, of course. So, the only explanation I have ATM is: Either you use a wrong order and hence has a mathematical error, or else your implementation is messed up (in which case we need to inspect code).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this