KurtCob

03-20-2001, 04:19 AM

Hello guys,

How can I multiply a vector by a matrix ?

Tnks

Kurt

How can I multiply a vector by a matrix ?

Tnks

Kurt

View Full Version : Matrix question (Not really an OGL Question)

KurtCob

03-20-2001, 04:19 AM

Hello guys,

How can I multiply a vector by a matrix ?

Tnks

Kurt

How can I multiply a vector by a matrix ?

Tnks

Kurt

Rudi_P

03-20-2001, 04:30 AM

Is it the maths your stuck on?

if so go to

http://147.4.150.5/~matscw/RealWorld/tutindex.html

Matrix multiplication

if so go to

http://147.4.150.5/~matscw/RealWorld/tutindex.html

Matrix multiplication

Bahamut_france

03-20-2001, 04:33 AM

Do you want do that?

[ a b c d

e f g h x [ x y z] ? http://www.opengl.org/discussion_boards/ubb/confused.gif

i j k l

m n o p]

[ a b c d

e f g h x [ x y z] ? http://www.opengl.org/discussion_boards/ubb/confused.gif

i j k l

m n o p]

Bahamut_france

03-20-2001, 04:35 AM

bad..... All caracters are not written....

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

Do You want that ???

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

Do You want that ???

KurtCob

03-20-2001, 07:15 AM

Yes, is exactly what I want.

Tnks

Best Regards

Kurt

Tnks

Best Regards

Kurt

coredump

03-20-2001, 11:28 AM

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

Vold X Matrix = Vnew

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

b

Randolph

03-20-2001, 12:44 PM

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] [a1*x1+b1*x2+c1*x3+d1*x4]

[a2 b2 c2 d2]*[x2]=[a2*x1+b2*x2+c2*x3+d2*x4]

[a3 b3 c3 d3] [x3] [a3*x1+b3*x2+c3*x3+d3*x4]

[a4 b4 c4 d4] [x4] [a4*x1+b4*x2+c4*x3+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).]

[a1 b1 c1 d1] [x1] [a1*x1+b1*x2+c1*x3+d1*x4]

[a2 b2 c2 d2]*[x2]=[a2*x1+b2*x2+c2*x3+d2*x4]

[a3 b3 c3 d3] [x3] [a3*x1+b3*x2+c3*x3+d3*x4]

[a4 b4 c4 d4] [x4] [a4*x1+b4*x2+c4*x3+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).]

john

03-20-2001, 05:31 PM

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).]

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).]

KurtCob

03-21-2001, 01:37 AM

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

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

jc

03-21-2001, 04:42 AM

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 = v1*m00 + v2*m10 + v3*m20 + v4*m30

b = v1*m01 + v2*m11 + v3*m21 + v4*m31

c = v1*m02 + v2*m12 + v3*m22 + v4*m32

d = v1*m03 + v2*m13 + v3*m23 + v4*m33

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

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 = v1*m00 + v2*m10 + v3*m20 + v4*m30

b = v1*m01 + v2*m11 + v3*m21 + v4*m31

c = v1*m02 + v2*m12 + v3*m22 + v4*m32

d = v1*m03 + v2*m13 + v3*m23 + v4*m33

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

KurtCob

03-21-2001, 05:08 AM

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

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

coredump

03-21-2001, 06:28 AM

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

b

KurtCob

03-21-2001, 07:02 AM

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

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

DaViper

03-21-2001, 07:20 AM

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

hope that helps

Chris

hope that helps

Chris

Randolph

03-21-2001, 01:04 PM

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 4*4 by 4*1, I surely can multiply 1*4 by 4*4! The result surely will be 1*4. I think that 1*4 is vector. You dont?

You wrote: "you can NOT premultiply a matrix with a vector". Beforehands, you explained, how it should be done. If i can multiply 4*4 by 4*1, I surely can multiply 1*4 by 4*4! The result surely will be 1*4. I think that 1*4 is vector. You dont?

john

03-21-2001, 03:08 PM

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 4*4 by 4*1, I surely can multiply 1*4 by 4*4! The result surely will be 1*4. I think that 1*4 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

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 4*4 by 4*1, I surely can multiply 1*4 by 4*4! The result surely will be 1*4. I think that 1*4 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

ffish

03-21-2001, 04:46 PM

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.

KurtCob

04-02-2001, 05:41 AM

Ok guys, so witch is the right way ?

This posted by Randolph

[a1 b1 c1 d1] [x1] [a1*x1+b1*x2+c1*x3+d1*x4]

[a2 b2 c2 d2]*[x2]=[a2*x1+b2*x2+c2*x3+d2*x4]

[a3 b3 c3 d3] [x3] [a3*x1+b3*x2+c3*x3+d3*x4]

[a4 b4 c4 d4] [x4] [a4*x1+b4*x2+c4*x3+d4*x4]

????

or this one posted by JC

a = v1*m00 + v2*m10 + v3*m20 + v4*m30

b = v1*m01 + v2*m11 + v3*m21 + v4*m31

c = v1*m02 + v2*m12 + v3*m22 + v4*m32

d = v1*m03 + v2*m13 + v3*m23 + v4*m33

???

Any help will be apreciated.

Thank you for the moment

Best regards

Kurt

This posted by Randolph

[a1 b1 c1 d1] [x1] [a1*x1+b1*x2+c1*x3+d1*x4]

[a2 b2 c2 d2]*[x2]=[a2*x1+b2*x2+c2*x3+d2*x4]

[a3 b3 c3 d3] [x3] [a3*x1+b3*x2+c3*x3+d3*x4]

[a4 b4 c4 d4] [x4] [a4*x1+b4*x2+c4*x3+d4*x4]

????

or this one posted by JC

a = v1*m00 + v2*m10 + v3*m20 + v4*m30

b = v1*m01 + v2*m11 + v3*m21 + v4*m31

c = v1*m02 + v2*m12 + v3*m22 + v4*m32

d = v1*m03 + v2*m13 + v3*m23 + v4*m33

???

Any help will be apreciated.

Thank you for the moment

Best regards

Kurt

KurtCob

04-02-2001, 10:43 AM

Ok guys, so witch is the right way ?

This posted by Randolph

[a1 b1 c1 d1] [x1] [a1*x1+b1*x2+c1*x3+d1*x4]

[a2 b2 c2 d2]*[x2]=[a2*x1+b2*x2+c2*x3+d2*x4]

[a3 b3 c3 d3] [x3] [a3*x1+b3*x2+c3*x3+d3*x4]

[a4 b4 c4 d4] [x4] [a4*x1+b4*x2+c4*x3+d4*x4]

????

or this one posted by JC

a = v1*m00 + v2*m10 + v3*m20 + v4*m30

b = v1*m01 + v2*m11 + v3*m21 + v4*m31

c = v1*m02 + v2*m12 + v3*m22 + v4*m32

d = v1*m03 + v2*m13 + v3*m23 + v4*m33

???

Any help will be apreciated.

Tnks

Best regards

Kurt

This posted by Randolph

[a1 b1 c1 d1] [x1] [a1*x1+b1*x2+c1*x3+d1*x4]

[a2 b2 c2 d2]*[x2]=[a2*x1+b2*x2+c2*x3+d2*x4]

[a3 b3 c3 d3] [x3] [a3*x1+b3*x2+c3*x3+d3*x4]

[a4 b4 c4 d4] [x4] [a4*x1+b4*x2+c4*x3+d4*x4]

????

or this one posted by JC

a = v1*m00 + v2*m10 + v3*m20 + v4*m30

b = v1*m01 + v2*m11 + v3*m21 + v4*m31

c = v1*m02 + v2*m12 + v3*m22 + v4*m32

d = v1*m03 + v2*m13 + v3*m23 + v4*m33

???

Any help will be apreciated.

Tnks

Best regards

Kurt

FoxDie

04-02-2001, 11:06 AM

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]+1*B[J+1,I+1].....

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]+1*B[J+1,I+1].....

KurtCob

04-04-2001, 02:12 AM

Sorry, but i didn't understand.

Tnks

Best regards

Kurt

Tnks

Best regards

Kurt

fleejay

04-04-2001, 07:22 AM

KurtCob the two methods are identical, bothj producing the same results, in the top method there is a name for each element in the matrix, in the bottom method each element in the matrix is accessed by a 2-dimensional index (think of a 2d array).

---

Fleejay

---

Fleejay

KurtCob

04-04-2001, 07:55 AM

Ok,

Thank you.

Best regards

Kurt

Thank you.

Best regards

Kurt

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.