How can I rotate the data in a 2D n by n matrix by an arbitrary angle?

292 Views Asked by At

How to rotate a matrix by 45 degrees?

So I found this post where someone shows images of a 45-degree rotation of a matrix. I would like to do the same thing, but for 120 degrees (Or for any other angle). They go from 5x5 matrix to a 9x9 matrix which is fine, but how do you know where to add the zeros, and what the new size of the matrix will be given the size of the original matrix and the new rotation angle?

In short, I want to rotate the data in the matrix itself, thanks :)