title: How do we rotate a tetris piece counter clockwise?
body: <p>I looked at the algorithm here for clockwise rotation, but I can't do it the other way around. So basically, for clockwise rotation, you need to multiply the transpose to a rotation matrix, but how do you do the same thing the other way around?</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public class rotation2 {
  
      public static int [][] multiplyMatrix(int [][] m1) {
          int [][] m2 = {{0,0,0,1},
                         {0,0,1,0},
                         {0,1,0,0},
                         {1,0,0,0}};
          int[][] result = new int[4][4];
  
          // multiply
          for (int i=0; i&lt;4; i++)
              for (int j=0; j&lt;4; j++)
                  for (int k=0; k&lt;4; k++)
                      result[i][j] += m1[i][k] * m2[k][j];
  
          return result;
      }
  
      public static int [][] multiplyMatrix2(int [][] m2) {
          int [][] m1 = {{0,0,0,1},
                         {0,0,1,0},
                         {0,-1,0,0},
                         {-1,0,0,0}};
          int[][] result = new int[4][4];
  
          // multiply
          for (int i=0; i&lt;4; i++)
              for (int j=0; j&lt;4; j++)
                  for (int k=0; k&lt;4; k++)
                      result[i][j] += m1[i][k] * m2[k][j];
  
          return result;
      }
  
      public static void printArray(int [][] array) {
          for(int row = 0; row &lt; array.length; row++) {
              for(int col = 0; col &lt; array[row].length; col++) {
                  if (array[row][col] &gt; 0) {
                      System.out.printf("1");
                  } else {
                      System.out.printf("0");
                  }
              }
              System.out.printf("\n");
          }
      }
  
      public static int [][] transpose(int [][] m1) {
          int m = 4;
          int n = 4;
          int c = 0;
          int d = 0;
  
          int[][] transpose = new int [n][m];
  
          for ( c = 0 ; c &lt; m ; c++ ) {
              for ( d = 0 ; d &lt; n ; d++ ) {
                  transpose[d][c] = m1[c][d];
              }
          }
          return transpose;
      }
  
      public static void main(String[] args) {
          int [][] m1 = {{1,0,0,0},
                         {1,0,0,0},
                         {1,1,0,0},
                         {0,0,0,0}};
  
          int [][] transpose = transpose(m1);
          printArray(transpose);
          transpose = multiplyMatrix(transpose);
          printArray(transpose);
  
          int [][] transpose2 = transpose(m1);
          printArray(transpose2);
          transpose2 = multiplyMatrix(transpose2);
          printArray(transpose2);
      }
  }
  </code></pre>
  
  <p>You don't transpose for counter clock rotation, right?</p>