How do you transform a matrix around its own origin?

42 Views Asked by At

Given a matrix of size n such as:

[ 1 2 3 ]
[ 4 5 6 ]
[ 7 8 9 ]

How do you reflect the matrix along the y-axis, x-axis, the line y=x, and the line y=-x?

For example, the matrix above reflected over the line y=x will yield:

[ 9 6 3 ]
[ 8 5 2 ]
[ 7 4 1 ]

I am hoping to have one equation that works for all three, with some variable representing the axis.

1

There are 1 best solutions below

0
On

Consider the matrix $$P=\begin{bmatrix} 0 & 0 & 1\\ 0 & 1 & 0\\ 1 & 0 & 0\\ \end{bmatrix}$$ Then, if $A$ is any $3\times 3$ matrix, the matrix $AP$ is the matrix obtained from $A$ by exchanging the first and third column, while $P^{-1}A$ is the matrix obtained from $A$ by exchanging the first and the third row. See Permutation matrices for more details. Note that a permutation matrix $P$ is an orthogonal matrix, so $P^{-1}=P^T$, where $P^T$ is the transpose of $P$.

Therefore, $(P^{-1}AP)^T=P^TA^TP$ is the matrix that performs the transformation you are looking for.