Rotation matrix

Remember that the method can be. (Here we are square matrix Ha.)

Counterclockwise rotation of matrix 90 °: on both sides of the first main diagonal elements interchanged, then the i-th row and row ni interchanged.

Matrix clockwise rotation 90 °: on both sides of the first sub-diagonal elements interchanged, then the i-th row and row ni interchanged.

 

For example, clockwise rotation of 90 ° for an AC codes:

void clockwise(int a[][4],int n)
{
     for(int i=0; i<n; ++i)
        for(int j=0; j<n-i; ++j)
            swap(a[i][j], a[n-1-j][n-1-i]); //以副对角线的对称位置。画个方阵看看就知道了。

    for(int i=0; i<n/2; ++i)
        for(int j=0; j<n; ++j)
            swap(a[i][j], a[n-1-i][j]);
}

Specific intuitive explanation see https://blog.csdn.net/qq_26525215/article/details/52076488

Guess you like

Origin blog.csdn.net/m0_38033475/article/details/92215673