View Full Version : Rotations sequences

memecs

08-17-2009, 05:01 PM

hello everyone, i got a problem with rotation matrices multiplication and i hope someone could help me tofigure that out...

So say that i want to perform a sequence of rotation in order xyz. Since opengl pre-multiplied it means that it's multiplying in this way:

Rz * Rx * Ry

now i've implemented the matrix Rz * Ry * Rx on my own and it looks exactly like the xyz matrix in the Matrix Table at the bottom of this link:

http://en.wikipedia.org/wiki/Euler_angles

comparing the two rotations i figured out that this matrix perform the following opengl sequence of rotation:

glRotated(az,0,0,1)

glRotated(ay,0,1,0)

glRotated(ax,1,0,0)

How is this possible? Where am I wrong?

thanks a lot

Aleksandar

08-18-2009, 05:48 AM

Nothing is wrong!

If we assume rotation matrices are denoted in the following way:

glRotated(az,0,0,1) = Rz

glRotated(ay,0,1,0) = Ry

glRotated(ax,1,0,0) = Rx

when you call glRotated(az,0,0,1) you, in fact, multiply matrix on the top of the current matrix stack (probably MODELVIEW) with your matrix Rz (right side multiplication)

C' = C * Rz

If you cumulatively multiply with Rz, Ry and Rx, respectively, the result is

C" = (((C * Rz) * Ry) * Rx)

So, new position of the vertex (i.e. resulting vector) after being transformed by resulting matrix is:

v' = (((C * Rz) * Ry) * Rx) * v = (C * (Rz * (Ry * (Rx * v))))

If you are "thinking in global coordinate-system", vertex is first rotated around X-axis (in global coordinate-system), than around Y and at last around Z-axis of global coordinate-system.

If you are "thinking in local coordinate-system", local coordinate-system is first rotated around Z-axis (both global and local systems are the same at this moment), than around local Y and at last around local X-axis.

The final result is the same. Only "the way of thinking" differs.

memecs

08-18-2009, 10:42 PM

thanks a lot you really helped me out with this...

By the way I kind of don't understand why given a sequence xyz inverting the order to RzRyRx give a rotation around the global axis (axis that never change position right???) and RxRyRz produce a rotation around the local axis?

... I kind of don't understand why given a sequence xyz inverting the order to RzRyRx give a rotation around the global axis (axis that never change position right???) and RxRyRz produce a rotation around the local axis? Neither of those statements is true. In both cases, you have Euler rotation sequences, which are neither global nor local. To achieve true global (which I call 'screen') or local rotations you have to take quite a different approach.

Aleksandar

08-19-2009, 02:13 AM

Let's make everything much clearer...

When you draw your objects, coordinates of the vertices are usually defined in so called local coordinate-system. The center of the local coordinate-system is located in the center of the object, or at the lower-left corner of the bounding box, or at some vertex, or something like that. The point of this is that you can model your objects locally and then translate/rotate/scale so that they are placed at appropriate position on the scene. If there is no transformation, objects will reside in the center of global (world) coordinate-system.

If we want to apply some transformations to the object, than we would write something like this:

Transf1();

Transf2();

Transf3();

DrawObject();

Because of the right matrix multiplication (take a look at the previous post), object will be transformed by Transf3() firstly, if you think in terms of global coordinate-system, than by Transf2() and at last by Transf1(). So, transformations are applied in reverse order.

But if we assume that transformations in fact transforms local coordinate-system, than local coordinate-system will be transformed by Transf1() firstly, than by Transf2(), and at the end by Transf3(). Now, transformations appear in the natural order. After all three transformations our local coordinate-system is transformed (translated/rotated/scaled) and will create/draw our object in such "awry" local coordinate-system. You can imagine the local coordinate-system as a coordinate-system tied to the object.

In both cases the transformations are exactly the same!

memecs

08-23-2009, 01:53 AM

thanks a lot everyone i think a got it now...

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.