# Matrix question (Not really an OGL Question)

Hello guys,

How can I multiply a vector by a matrix ?

Tnks
Kurt

Is it the maths your stuck on?

Matrix multiplication

Do you want do that?

[ a b c d
e f g h x [ x y z] ? i j k l
m n o p]

bad… All caracters are not written…

I wrote: (matrice 4x4) x ( vector 1x3)

Do You want that ???

Yes, is exactly what I want.

Tnks
Best Regards
Kurt

multiplying a vector by a matrix will give you a vector.

Vold X Matrix = Vnew

the elements in Vnew are the dot products of Vold and each row/column in Matrix.

b

If you POST-multiply the matrix, then vector should be column. If you PRE-multiply the matrix vector is string. Surely, you will get same type of vector as a result. So, we have:
[a1 b1 c1 d1] [x1] [a1x1+b1x2+c1x3+d1x4]
[a2 b2 c2 d2][x2]=[a2x1+b2x2+c2x3+d2x4]
[a3 b3 c3 d3] [x3] [a3
x1+b3x2+c3x3+d3x4]
[a4 b4 c4 d4] [x4] [a4
x1+b4x2+c4x3+d4*x4]
in occasion of post-multiplication, or analogically in pre-multiplication. The generic rule is that string is multiplied by column.

[This message has been edited by Randolph (edited 03-20-2001).]

post multiply? pre multiply? vectors and matricies? surely you jest?

incidentially, you can’t multiply a 4x4 matrix by a 1x3 vector. furthermore, a 1x3 is a single ROW; you want a column vector (i.e. 3x1). Remember, its number_of_rows x number_of_columns (y dimension FIRST)

if you have two matricies, A and B of dimension a x b and c x d respectively, then in order to multiply A and B together then b MUST == c (and the dimension of the result is a x d). this is just matrix stuff, btw, nothing clever about opengl.

so, you CAN’T multiple 4x4 by a 1x3 (or a 3x1, for that matter) because 4!=3

but you CAN multiply a 4x4 by a 4x1:

ie. 4x4 * 4x1
| |
same!

uhm. yes. <tries to summon strength to explain matrix mul>
no, sod it. each element of the final vector is its corresponding ROW of the matrix multipled by the vector.

oh, and another thing: you can NOT premultiply a matrix with a vector.

cheers
John

[This message has been edited by john (edited 03-20-2001).]

Tnks John,

So can you post how can I multiply a 4X4 Matrix by a 1X4 vector ? (Sorry, it looks really use, and I should know this), but I forgot how to do this.

So, any help will be apreciated.

Tnks
Best Regards
Kurt

Hi, if u want to multiply a vector by a matrice it should look like this:

Vector = V1 V2 V3 V4 And Matrix = M00 M01 M02 M03
M10 M11 M12 M13
M20 M21 M22 M23
M30 M31 M32 M33

Vector*Matrix = [a,b,c,d]

where
a = v1m00 + v2m10 + v3m20 + v4m30
b = v1m01 + v2m11 + v3m21 + v4m31
c = v1m02 + v2m12 + v3m22 + v4m32
d = v1m03 + v2m13 + v3m23 + v4m33

To multiply vector and matrices the dimensions of boths should look like this:

M [n m] * N[m t] = Res[n t]

Hope il will help

Tnks JC,

Is it what I was looking for.

Does anyone know where could I find the matrix that OpenGL is using when we use glRotate and glTranslate ?

I want to multiply all the vertices of my model, using the way that OpenGL is rotating, scaling, translating and so one, because then when I export a file, I will have the right coordinates…Am I right ?

Tnks
Best regards
Kurt

glRotate and glTranslate affect the modelview matrix, if in that mode. the matrix itself is a one dimensional array of 16 floats. using glMultMatrix you can use your own user-defined matrix.

b

Ok, tnks again.

Just one more question, if I make a rotation in the X, Y or Z Axis, witch os the elements of the matriz will be the cos and sin ? or when I use glTranlate, witch element of the matriz will be the value translated in X, Y, Z…hope I’m clear enough, with my question.

Tnks
Best regards
Kurt

everything you are looking for us here: http://shiva.missouri.edu:88/SGI_Developer/OpenGL_PG/27690#X

hope that helps
Chris

TO John:
You wrote: “you can NOT premultiply a matrix with a vector”. Beforehands, you explained, how it should be done. If i can multiply 44 by 41, I surely can multiply 14 by 44! The result surely will be 14. I think that 14 is vector. You dont?

quote:
TO John:
You wrote: “you can NOT premultiply a matrix with a vector”. Beforehands, you explained, how it should be done. If i can multiply 44 by 41, I surely can multiply 14 by 44! The result surely will be 14. I think that 14 is vector. You dont?

yes, you can, and that’s right. but the guy was talking about column vectors… okay, so maybe he wasn’t and it was just a massive assumption on my part =) but, given that verticies are specified by a column vector, then you can NOT premultiply a column vector by a matrix, but you CAN premultiply the transpose of a column vector by a matrix. subtle difference in that you need to do an extra step

ie. if V = [ 1 2 3 4 ] ’ and M is a 4x4 matrix, then

MV works

VM does NOT work

but

V’M DOES work

(where ’ is the transpose operator)

(oh, and V’V is a scalar, and MM is a 4x4 matrix and VV’ does nto work, either)

cheers,
John

I agree with everything John says. One thing that may help people with questions on the topic is a good linear algebra book. Our first year undergrad book was Gilbert Strang’s “Introduction to Linear Algebra” and I highly recommend it. I still refer to it if I have problems. Early chapters are easy to understand and you can really expand your LA knowledge in some of the later chapters. It’s also very readable.

Ok guys, so witch is the right way ?

This posted by Randolph

[a1 b1 c1 d1] [x1] [a1x1+b1x2+c1x3+d1x4]
[a2 b2 c2 d2][x2]=[a2x1+b2x2+c2x3+d2x4]
[a3 b3 c3 d3] [x3] [a3
x1+b3x2+c3x3+d3x4]
[a4 b4 c4 d4] [x4] [a4
x1+b4x2+c4x3+d4*x4]
???

or this one posted by JC

a = v1m00 + v2m10 + v3m20 + v4m30
b = v1m01 + v2m11 + v3m21 + v4m31
c = v1m02 + v2m12 + v3m22 + v4m32
d = v1m03 + v2m13 + v3m23 + v4m33

???

Any help will be apreciated.
Thank you for the moment
Best regards

Kurt

Ok guys, so witch is the right way ?
This posted by Randolph

[a1 b1 c1 d1] [x1] [a1x1+b1x2+c1x3+d1x4]
[a2 b2 c2 d2][x2]=[a2x1+b2x2+c2x3+d2x4]
[a3 b3 c3 d3] [x3] [a3
x1+b3x2+c3x3+d3x4]
[a4 b4 c4 d4] [x4] [a4
x1+b4x2+c4x3+d4*x4]
???

or this one posted by JC

a = v1m00 + v2m10 + v3m20 + v4m30
b = v1m01 + v2m11 + v3m21 + v4m31
c = v1m02 + v2m12 + v3m22 + v4m32
d = v1m03 + v2m13 + v3m23 + v4m33

???

Any help will be apreciated.
Tnks
Best regards

Kurt

A is matrix 4X4
B is matrix 4x1

A=(0,5,4,3)
(1,0,0,8)
(8,4,4,5)
(1,-2,3,1);
B=(0)
(8)
(0)
(2);

If you multiplying matrixes the rows of
matrix A must be same as columns of matrix B.
C=A*B

I-row index
J-column index

C[I,J]=A[I,J]B[J,I]+A[I+1,J+1]+1B[J+1,I+1]…