Advertisement

Rotation Matrix, By Hand

Started by June 24, 2000 04:46 PM
12 comments, last by Esap1 24 years, 5 months ago
lets say I got a class: class Matrix_class { float Matrix[4][4]; void TranslationMatrix(float x,float y,float z); void RotationMatrix(float Xa, float Ya,float Za); } Ive already written the TranslationMatrix() function(yes, I know, its simple, but Im still happy), but I need a little help with the rotation. The function should set Matrix, to a Rotation Matrix that takes in acount the Angles, Xa,Ya,Za. Thanks for the help(and I searched for similear posts, but never found one where they did it by hand). later,
And what about a MatrixMultiply() function, that would be compatible with OpenGL''s Matrices, anyone?
Advertisement
Witchlord, I know you know the answer!
There's a lot of sin's cos's & some theta's & some phi's

in 2D i believe its
[ [cos(theta), 0]
[0, -sin(theta)] ]
though I may have every-which-thing reversed
Draw a picture, you do know trig right?

I cant seem to find my cg book at the moment, otherwise I'd have the 3D answer ...

Edited by - Magmai Kai Holmlor on June 24, 2000 12:02:04 AM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
I dont know enough trig to figure it out. Ill probaly be learning what I need this year in school(only a Freshmen, in Highschool). Ill try to figure it out, but if you could give me the full equation that would really help, thanks,
I have just figured out, its impossible for me, I dont understand cos, sin, enough, could someone at least help with that(I know 90% of the people on this board understand that). Thanks for any help you can give me
Advertisement
No trig eh? I suppose that means no linear algebra either?
I hope you like math


Here are the three Rotation matricies:

Rx
[1, 0, 0, 0]
[0, cos(theta), sin(theta), 0]
[0, -sin(theta), -cos(theta), 0]
[0, 0, 0, 1]

Ry
[cos(theta), 0, -sin(theta), 0]
[0, 1, 0, 0]
[-sin(theta), 0, cos(theta), 0]
[0, 0, 0, 1]

Rz
[cos(È), sin(È), 0, 0]
[-sin(È), cos(È), 0, 0]
[0, 0, 1, 0]
[0, 0, 0, 1]

the È's are about the respective axi

Do you know how to multiple matricies? hehe well atually, do you have a TI-92? Cause you (nor I) will not doing that by hand!

heheh it didnt take those Θ's very well did it? those are thetas...



Edited by - Magmai Kai Holmlor on June 25, 2000 1:23:10 AM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
The second before you wrote that I copied it out of a book I found, But it wouldnt work because I didnt convert it to degrees, STUPID ME, I just did Ya=Ya*(PI/180), and HAHA, It works, Im so happy. Now, would you write a function to multiply to 4x4 Matricies. Thanks for posting too.
Ok here we go:
(You know, there''s a reason why you don''t do this yourself )

a is about Rx
b is about Ry
c is about Rz
Rotate(a, b, c):

[cos(b)*cos(c), cos(b)*sin(c), -sin(b), 0]

[-cos(a)*sin(c)-sin(a)*sin(b)*cos(c), cos(a)*cos(c)-sin(a)*sin(b)*sin(c), sin(a)*cos(b), 0]

[cos(a)*sin(b)*cos(c)+sin(a)*sin(c), cos(a)*sin(b)*sin(c)-sin(a)*cos(c), -cos(a)*cos(b), 0]

[0, 0, 0, 1]

note that is is only one possible solution - there are many (all produce the same result, more or less)
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
well damn it, you couldn''t posted that few minutes earlier and saved me all that typing! ;-P

... a 4x4 multipler?

oh god... matrix math is hard
Do you know the row & column rules?

M1[nxb] * M2[bxm]
the b''s gotta be the same - but i guess you''re just gonna mult 4x4''s arent ya?

i is the row, j is the col

M3 = M1 * M2
M3[i,j] = Sum(M1[row i] * M2[col j])


for(int i=0;i<4;i++)
{
float sum =0;
for(int j=0;j<4;j++)
{
sum += M1[i,j] * M2[j,i]
}
M3[i,j] = sum;
}
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement