I asked yesterday for a solution for rotating an 2d array with n*m. I get this link as answer: How do you rotate a two dimensional array?
I tryed my best and I thougt it works fine. And yes it works for an n*n array but if n and m are different I get an IndexOutOfBounds Error and I have no Idea why.
Here is my code:
public void rot90DegRight(){
//get Matrix
this.Matrix = getMatrix();
int rows = Matrix.length;
int cols = Matrix[0].length;
// create a mirror of current matrix
RGBColor[][] mirror = getMatrix();
// create a new matrix
for (int i = 0; i < rows; i++){
for (int j = 0; j < cols; j++){
Matrix[j][rows - i - 1] = mirror[i][j];
}
}
// replace cols count with rows count
int tmp = rows;
rows = cols;
cols = tmp;
}
Thank you a lot for helping.