# Matrix Transpose

All square matrices have a Main Diagonal. This is the row of numbers that goes diagonally along the matrix from the top left to the bottom right. For a 4x4 matrix, these are elements: (0,0), (1,1), (2,2), (3,3). Another way to define the main diagonal is elements which have the row and column index.

$$\begin{bmatrix} \textbf{A} & e & i & m\\ b & \textbf{F} & j & n\\ c & g & \textbf{K} & o\\ d & h & l & \textbf{P} \end{bmatrix}$$

To transpose a matrix, flip it along it's main diagonal. The image below shows the transpose operation. You may have noticed that transposing a Column Major matrix gives it the same logical topology as if it where converted to a Row Major matrix. The transpose operation can be used to change the logical topology of a matrix. The code sample below shows a simple Transposed function.

mat4 Transposed(mat4 m) {
mat4 r;

r.v = m.v;
r.v = m.v;
r.v = m.v;

r.v = m.v;
r.v = m.v;
r.v = m.v;

r.v = m.v;
r.v = m.v;
r.v = m.v;

return r;
}

// mat 2 and 3 transpose functions are similarly trivial