# concatenating rotation around different origins

This topic is 3165 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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:

translate(x,y,z);
multiply_matrix(m);
translate(-x,-y,-z);

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 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
R1
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
q.e.d.

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 on other sites
uh.. hmm..

no,implementation is ok.. but you gave me a couple of things to think about..

thank you!

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632997
• Total Posts
3009791
• ### Who's Online (See full list)

There are no registered users currently online

×