# Pre and Post Multiplication World Space Transform Matrix ambiguity

I'm currently studying about world space transformation matrices and encountered some confusion regarding their application in different matrix orders (row major vs column major).

Context

In row major order, a point is represented as $$\begin{bmatrix} x,y,z \end{bmatrix}$$ In column major order, the same point is represented as $$\begin{bmatrix} x \\ y \\ z \end{bmatrix}$$

World Space Transformation

For column major order, we use post-multiplication: $$P1 = WST * p1 = S * Rx * Ry * Rz * T * p1$$

For row major order, it's we use pre-multiplication: $$P2 = p2 * WST = p2 * T * Rz * Ry * Rx * S'$$

However, I feel, for row major it should instead be: $$P2 = p2 * WST' = p2 * T' * Rz' * Ry' * Rx' * S'$$ where ' denotes transpose of the matrix.

My Reasoning

Both P1 and P2 represent the same transformed point, just in different orders (column major vs row major).

So, $$P2 = P1' = (S * Rx * Ry * Rz * T * p1)'$$

Since, $$(AB)' = B'A'$$

We can say that, $$P2 = p1' * T' * Rz' * Ry' * Rx' * S' = p2 * T' * Rz' * Ry' * Rx' * S'$$ (as $$p1' = p2$$)

• Did you miss a transpose on S for the third equation? Commented Jan 31 at 11:59
• Also, are these matrices row major or column major? Commented Jan 31 at 15:11
• @pmw1234 yup that was a typo, I fixed it. $S, Rx, Ry, Rz, T$ are 4x4 matrices (scaling, rotation, translation) Commented Jan 31 at 19:08

I was going to do a bunch of fancy matrices but I really I think your confusion is surrounding matrix-major order.

A matrix is either column major or row major. It's best to pick one and stick to it. Such as in OpenGL we almost always talk column major order which is the world of post multiply. So for the rest of this question I will stick to column major.

Transposing a column major matrix doesn't change it into a Row major matrix, we still have a column major matrix it is just transposed. We can make equivocations between row and column major but the two worlds really should be kept separated.

So when we talk about multiplying column major matrices we should be careful to use only column major matrices in the calculation.

$$p_1 = C*p1$$ // C and p1 are column major

$$p_2 = p1^T *C^T$$ // the superscript indicates transpose

$$p_1 == p_2$$

These 3 statement make sense only because we are talking column major matrices. We can switch between row and column major but it should be a clean break so to speak.

The question seems to treat the matrices kind of as both at the same time. That will get you into trouble quickly. Even though we all know that if we transpose a column major matrix it is equivalent to a row major matrix, it is much better to say it is a column major matrix transposed.

I'm not sure if I got to the heart of your question here, but hopefully it helps clear things up a little.

A Column Major 4x4 matrix is laid out like this:

$$\begin{bmatrix} a & e & i & m \\ b & f & j & n \\ c & g & k & o \\ d & h & l & p \end{bmatrix}$$ Think of it as 4 4x1 vectors stacked next to each other.

A row major 4x4 matrix has a data layout out like this:

$$\begin{bmatrix} a & b & c & d \\ e & f & g & h \\ i & j & k & l \\ m & n & o & p \end{bmatrix}$$ Think of it as 4 1x4 vectors stacked on top of each other.

Notice that the diagonals of each have the same values and that the transpose of each produces the other.

• I still quite don't understand why the transpose of row major matrix will not be a column major matrix? Like the transpose of 4x1 matrix is supposed to be 1x4 right? Commented Jan 31 at 23:45
• If you want to convert between the two systems, then take the transpose and call it row major. But when working with a matrix doing translation, rotation, scale, it is done in the matrix major order the matrix was defined to be in. So yeah you can switch and it's easy, but do work in one system or the other. For example math libraries are often written to work in one system, like column major. All the operations follow column major order, if some are written in row major and some written in column major then chaos will result. Commented Feb 1 at 0:20
• Totally agree with that.. However my question was that if we follow the column-major order we define WST matrix as $P1=WST∗p1=S∗Rx∗Ry∗Rz∗T∗p1$ So shouldn't we define the WST matrix as $P2=p2∗WST′=p2∗T′∗Rz′∗Ry′∗Rx′∗S'$ when dealing with row-major order Commented Feb 1 at 15:04
• And what I am saying is that your question doesn't make any sense. Equation 1 is talking column major, equation 2 is talking row major, and equation 3 is talking row major transopose. But in order for equation 2 to be meaningful in the first place that matrices need to be in row major order which is the transpose of the matrices in equation 1. But if equation 2 is talking column major then it is incorrect since the matrix data hasn't been converted to row major format. So the equations are switching back and forth without defining the matrix-major order and any meaning is getting lost. Commented Feb 1 at 15:27
• $P2, p2$ is row major (1x4) and $P1, p1$ are column major (4x1), all other matrices are 4x4 Commented Feb 1 at 23:22