PDA

View Full Version : Rotational Matrices



Deiussum
12-09-2000, 02:45 PM
I understand how the basic matrices for rotating around the X,Y,Z axes work, but I don't quite get how to calculate the matrix for other rotations work. For instance if you were to do glRotatef(1.0, 0.71, 0.0, 0.71); How would you calculate the matrix? I read a formula for that in the Red Book, but it used notation that was a bit above my head. http://www.opengl.org/discussion_boards/ubb/smile.gif

Sourpotato
03-09-2004, 10:22 PM
I have the same problem, the formula is hard to figure ,especially what the uu(t) is ?do you got the idea now

Relic
03-09-2004, 11:21 PM
Simple linear algebra. http://www.opengl.org/discussion_boards/ubb/wink.gif

Look at the formula in the RedBook appendix F again, it's all there.
u is the normalized rotation axis as column vector.
[u * u^T] is a matrix.
You multiply a column vector u with the transposed vector u^T, a row vector.
A dot-product would be row * column instead.
For example a 3x1 * 1x3 vector multiplication gives you a 3x3 matrix result.

It's called "outer multiplication", in contrast to the "inner multiplication" for the dot-product.
This should be the theory: http://mathworld.wolfram.com/LinearAlgebra.html

Sourpotato
03-09-2004, 11:23 PM
Now , i've deduced in some way.but there is some problem during my deduction, please give me comments or correction .

for example if glRotate(50,1,0,0);

then according to the rotation formula given by the red book edition 2 in the page 672.
the formula here is:
let v =( x,y,z),u = v/| |v| | = (x',y',z')
also
S = { 0 -z',y',
z',0,-x',
-y',x',0
}
M = uuT + cos(alpha)(I-uuT) + sin(alpha)S;

here the deduction goes:

the v = (1,0,0) ,| |v| | = sqrt(1^2 + 0^2 + 0^2) = 1.
so u= v/| |v| | = {x',y',z'} = (1,0,0) too;

S = { 0 -z',y',
z',0,-x',
-y',x',0
} = {0,0,0,
0,0,-1,
0,1,0 };

S* sin(alpha)
= {
0,0,0,
0,0,-sin(alpha)
0,sin(alpha),0
};

uuT = { 1,0,0,
1,0,0,
1,0,0
};

I is identity matrix;
so I - uuT =
{
0,0,0,
-1,1,0,
-1,0,1
}

the -1 in the column one should be erased,but i don't have idea how to erase it,

cos(alpha)(I - uuT) =
{
0,0,0
0,cos(alpha),0
0,0,cos(alpha)
}


cos(alpha)(I - uuI) + sin(alpha)S
=
{
1,0,0,0,
0,cos50,-sin50,0
0,sin50,cos50,0
0,0,0,1
}
}

Relic
03-09-2004, 11:33 PM
Your uuT is wrong



1 1 0 0
0 * 1, 0 0, = 0 0 0
0 0 0 0

Sourpotato
03-10-2004, 12:38 AM
Oh,God,Relic, i adore you, you solved my problem.thanx ,greatly

Sourpotato
03-10-2004, 04:38 AM
Now ,relic, i have further problem,is this deduction reversible ?? i mean , if i get the rotation matrix first,can i get the get the rotation angle, and the rotating vector. i think this is very important , because . this way , we can smoothly show the rotating process once we know the the destination axis direction.

[This message has been edited by RunningRabbit (edited 03-10-2004).]

Relic
03-10-2004, 05:11 AM
Not sure about a direct way, but here's a general solution for Euler angles: http://www1.acm.org/pubs/tog/GraphicsGems/gemsii/unmatrix.c

Sourpotato
03-10-2004, 06:16 AM
[QUOTE]Originally posted by Relic:
Not sure about a direct way, but here's a general solution for Euler angles:

Not sure how to use this unmatrix ..~~~

it turn out that i am spending the whole night doing the matrix mathamatics. http://www.opengl.org/discussion_boards/ubb/frown.gif

the {x,y,z} is normalized vector

the cos(alpha) = (r3z + r1x + r2y -1)/2

and the x:y:z = (r2z - r3y) : (r3x-r1z) : (r1y - r2x)

it's not end , but i would test it tomorrow.

what a headache night.thanx very much for your help.

[This message has been edited by RunningRabbit (edited 03-10-2004).]

Relic
03-10-2004, 10:45 PM
Here's an idea:
If you can deduct the Euler angles from a rotatioinal matrix with the given code, you can express the individual rotations as quaternions, multiply the quaternions and as they are expressed in an angle and an axis, this your result.

However, if you are in a program which uses OpenGL to draw something at a 3D orientation and the code is under your control, there shouldn't be the necessity to reverse-engineer matrices.
All rotations could be expressed as quaternions, too, and you always have the angle plus axis notation from the beginning.

[This message has been edited by Relic (edited 03-10-2004).]

harsman
03-11-2004, 12:16 AM
If R is the rotation matrix that rotates from orientation O1 to O2 then the eigenvector of R asociated with the eigenvalue 1 is the rotation axis. This is intuitive since the rotation axis is the only vector that stays unchanged during rotation.

Relic
03-11-2004, 05:13 AM
Cool, which somehow makes "I - uuT" look familiar to eigenvalue calculations.
I bet I know the next question. http://www.opengl.org/discussion_boards/ubb/wink.gif

Sourpotato
03-11-2004, 06:40 AM
To Relic
for a face in the 3D model,if we can know the face's the "normal vector" and "up vector" . we can construct the rotation matrix immediately to make face orient to the screen/user.but we would like to make show whole rotating process instead of make the face prompt immediately, we need to get the euler angle .

to harseman ,may i contend you with this little question.

if the begining matrix is identity matrix , and rotating matrix is
[ -1,0,0 ,
0,0,-1,
0,-1,0
]

in this case, i say ,there is no eigenvalue to utilize.

03-22-2004, 11:37 PM
I got answer finally, the quaternion will work to do the interpolation between any arbtary rotation angle/matrix.

http://www.cs.berkeley.edu/~laura/cs184/quat/quaternion.html