首页 > 代码库 > Rotate Image

Rotate Image

 

参照计算机图形学图形变换即可。

技术分享
public class Solution {
    
    public void rotate(int[][] matrix) {
        if(matrix.length<=1)return ;
        float dip=(float) ((matrix.length-1)/2.0);
        int[][] res=new int[matrix.length][matrix.length];
        for(int i=0;i<matrix.length;i++)
            for(int j=0;j<matrix.length;j++)
            {
                float x=i-dip;
                float y=j-dip;
                float newX=y+dip;
                float newY=-x+dip;
            //    System.out.println(newX+"    "+newY);
                res[(int)newX][(int)newY]=matrix[i][j];
            }
        for(int i=0;i<matrix.length;i++)
            for(int j=0;j<matrix.length;j++)
                matrix[i][j]=res[i][j];
    }
}
View Code

 

Rotate Image