• Create Account

# Matrix composition, transpose and multiplication order

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Volgogradetzzz  Members   -  Reputation: 432

Like
0Likes
Like

Posted 21 June 2012 - 01:53 AM

Hello. I digging matrix math and I have some misunderstanding. Please take a look at actionScript API:
I'm confused with words:

The first three rows of the matrix hold data for each 3D axis (x,y,z). The translation information is in the last column.

1. But that matrix on the picture is column-major matrix (sinse translation is last column), and not rows but columns should hold data for each 3D axis. Right?
2. In the case that this matrix is column-major the standart MVP matrix multiplication will not work sinse matrises are transposed. And in order to make it work I need transpose each matrix to make them row-major or multiplicate them in reverse order and transpose the result. Right?

### #2RubyNL  Members   -  Reputation: 154

Like
0Likes
Like

Posted 23 June 2012 - 02:20 PM

Usually you note vectors as column vectors, in this form:

x
y
z
1

Where the last 1 would be 0 for directional vectors, and 1 for positions. This would work fine with the matrix given there (if you premultiply with the matrix as it's given there, which you usually do). If you work out the multiplication by the vector above, you get a new column vector:

scaleX * x + tz
scaleY * y + ty
scaleZ * z + tx
1

So basically, you scaled the axes by scaleX, scaleY, scaleZ and then translated everything with tx, ty, tz.

### #3RubyNL  Members   -  Reputation: 154

Like
0Likes
Like

Posted 23 June 2012 - 02:23 PM

Oh, what I was trying to say is that the matrix given there seems to be correct to me. I don't know what exactly a column-major matrix is, but the matrix seems to do the job for column vectors.

### #4Cornstalks  Crossbones+   -  Reputation: 6807

Like
1Likes
Like

Posted 23 June 2012 - 02:36 PM

1. But that matrix on the picture is column-major matrix (sinse translation is last column), and not rows but columns should hold data for each 3D axis. Right?

No. That picture tells you nothing about whether or not a matrix is row/column major. Row/column order has to do with how the matrix is stored in memory. You still write it the same mathematically. Take a look at this Wikipedia page. You'll see the matrix:

There are lots of ways to store this matrix in memory, but the two most popular ways will be either row or column major layouts. Regardless of how it's stored in memory though, it's still written the same in mathematical notation.

Here's another example. Say you have the vector (1, 2, 3). Since we'll follow normal mathematical conventions, this means that x = 1, y = 2, and z = 3. However, this doesn't tell us anything about how this vector is stored in memory. You could have a struct like this: struct A { float x, y, z; }; and another struct like: struct B { float z, y, x; };. Both structs can represent this vector (1, 2, 3), and whenever you mathematically write this vector (like I've been doing in this paragraph), you always write it as (1, 2, 3), regardless of the fact that these two structs have a different internal memory layout.

Mathematically, row/column order means nothing, because you always write the matrix the same. It only matters when you're using a computer, because that matrix is stored in memory, and you need to know how to access that memory properly so you get the right matrix out of it.
[ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

### #5Volgogradetzzz  Members   -  Reputation: 432

Like
0Likes
Like

Posted 23 June 2012 - 11:33 PM

Oh. It seems that I was wrong when I said about row/column major

. I wanted to say that if we have vector on the left (row vector) then matrix on the right should have it's basis vectors as rows (assuming that matrix is transformation) and translation vector should be bottom row. And if we have vector on the right (column vector) then columns of the matrix are basis vectors and translation vector is the rightmost column. And the link above says that 3D matrix holds basis vectors as rows but translation vector is right column. It definitely should not work I think.

Edited by Volgogradetzzz, 23 June 2012 - 11:37 PM.

### #6RubyNL  Members   -  Reputation: 154

Like
0Likes
Like

Posted 24 June 2012 - 05:51 AM

It works, if you use column vectors and premultiply with that matrix.
Do you know how matrix multiplication works? Because if you work the multiplication out, you get the desired result (as I stated in my post earlier).
Here is how you should multiply matrices (you can treat a column vector as a 1x4 matrix):