Sign in to follow this  
xiaowei

multiple rotations

Recommended Posts

xiaowei    122
hello there, i have a lil prblem with multiple rotations. Ok, let start. I have a rotation matrix for Y-axis rotation, a translation matrix, a point P and a point M. I wnat to rotate point P around Point M. The first rotation works. I do P (1,0,1) M(3,0,1)
moving point P at -M coordinates

        |1 |
        |0 |
        |1 |
________|1 |
1 0 0 -3|-2|
0 1 0  0| 0|      Point P has been translated at -M coordinates,
0 0 1 -1| 0|      M is now "at 0,0,0".
0 0 0  1| 1|


rotating at 15 degrees around y-axis


                   |-2|
                   | 0|
                   | 0|
___________________| 1|____
0.966   0 -0.2588 0|-1.9319|
  0     1     0   0|  0    |
-0.2588 0  0.966  0|0.5176 |    P has been rotated
  0     0     0   1|1      |


moving P at +M koordinates


       |-1.9319 |
       |   0    |
       |0.5176  |
_______|   1    |
1 0 0 3|1.0681|
0 1 0 0| 0    |      Point P has been translated at -M koordinates,
0 0 1 1|1.5176|      M is now "at 0,0,0".
0 0 0 1| 1    |


P (1.0681,0,1.5176)

So far so good. Now my problem is... If i want to rotate the rotatet point P again around M I get wrogn values for P. ------------------------------- rotate again with P(1.0681,0,1.5176) M is still 3,0,1
moving point P at -M coordinates

        |1.0681 |
        |0      |
        |1.5176 |
________|1      |
1 0 0 -3|-1.9319|
0 1 0  0| 0     |      Point P has been translated at -M coordinates,
0 0 1 -1|0.5176 |      M is now "at 0,0,0".
0 0 0  1| 1     |


rotating at 15 degrees around y-axis


                   |-1.9319|
                   | 0     |
                   | 0     |
___________________|0.5176 |
0.966   0 -0.2588 0|-2.000 |
  0     1     0   0|  0    |
-0.2588 0  0.966  0|1.000  |    P has been rotated
  0     0     0   1|1      |


moving P at +M koordinates


       |-2.000  |
       |   0    |
       | 1.000  |
_______|   1    |
1 0 0 3|   1    |
0 1 0 0|   0    |      Point P has been translated at -M koordinates,
0 0 1 1|   2    |      M is now "at 0,0,0".
0 0 0 1|   1    |


P (1,0,2) 

but this is wrong. can anyone explain to me why the second rotations does not work ? For the 2nd rotation P should be 1.2679, 0, 2. I get the correct P if i rotate once at 30 degrees. But 2 times 15 degrees doesnt work. can an one help me ? I know, OpenGl computes backwards. OpenGl wants it like that T(+)*R*T(-) but on computing it on the paper is this order T(-)*R*T(+) greetings, xiaowei

Share this post


Link to post
Share on other sites
haegarr    7372
The matrices/vectors you've posted contain several errors. One is that you seem to use a definition like

[ cos 0 -sin 0 ]
[ 0 1 0 0 ]
[ -sin 0 cos 0 ]
[ 0 0 0 1 ]
for a rotation. That would be wrong, because only 1 of the sine terms have to show a negative sign!

In your 1st application that doesn't play a role since you multiply it w/ the z component of the vector which is 0, so it looks like being correct, but it isn't. Later, in the 2nd application, z isn't 0, and the error has an effect.


EDIT
Quote:
Original post by xiaowei
I know, OpenGl computes backwards.
OpenGl wants it like that T(+)*R*T(-)
but on computing it on the paper is this order
T(-)*R*T(+)

Then you know more than I do ;) Seriously, OpenGL uses column vectors while Direct3D uses row vectors. Both ways are legal math.

[Edited by - haegarr on November 23, 2007 3:28:17 AM]

Share this post


Link to post
Share on other sites
xiaowei    122
you right, i'Ve just found the error.
according to opengl i mean

if you do

rotation
scale
translation

opengl performs translation first, followed by scale and then the rotation.


greetings xiaowei

Share this post


Link to post
Share on other sites
haegarr    7372
Quote:
Original post by xiaowei
according to opengl i mean

if you do

rotation
scale
translation

opengl performs translation first, followed by scale and then the rotation.

I know what you mean. The problem is that there're some dependencies, so that a statement like "computes backward" is IMHO just insufficient. OpenGL applies transformations exactly as they should be applied. The correspondence of API invocations and math is described in the following:

(1) OpenGL uses column vectors. That means that a transformation is done like
p' := M * p
where M denotes the transformation and p the geometry (e.g. a vertex point).

(2) glTranslate, glRotate, glScale mean a matrix multiplication from the right. That is important because matrix multiplication isn't commutative. That means that the order
glRotate(...);
glTranslate(...);
is mathematically like
M := R * T
Due to this one can say "the order of OpenGL commands is exactly the same as the order of transformations" when written down to paper!

(3) The order in which concatenated matrix multiplications is applied plays no role. That means that
( M1 * M2 ) * M3 == M1 * ( M2 * M3 )
Notice that the order of the multiplications, and not the order of matrices plays no role!

Now, remembering that column vectors are nothing else than matrices with just 1 column, from the above one can see that a invocation sequence like
glRotate(...);
glTranslate(...);
glVertex(...);
means
p' := R * T * p
== ( R * T ) * p
== R * ( T * p )

The 1st correspondence above is used by OpenGL: It stores just the product of all matrices onto its matrix stack and applies it as a whole to the geometry.

The 2nd correspondence above is what can be used to understand what happens to the geometry: The geometry is translated, and the result is rotated. Due to this one can say "the order of OpenGL commands is exactly the reverse as the order of transformations is".

So, one can say the order is the same, and one can say it is the reverse. Both statements can be justified.

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