title: Rotation using Matrix in Java - Code not working
body: <p>We were giving a this program in class and asked to try it our at home but it doesn't work, I'm guessing there is something wrong with the algorithm. Can someone help me out?</p>
  
  <pre><code>import java.awt.Graphics;
  import javax.swing.JApplet;
  
  
  public class rotationalTransformation extends JApplet {
      int[] x=new int[3];
            int[] y=new int[3];
             int[][] tMatrix=new int[3][3];
  
          int no_pts=3;
  
     public void start()
     { 
  
            x[0]= 10;
            x[1]= 20;
            x[2]= 30 ;
            y[0]= 10;
            y[1]= 30;
            y[2]= 10 ;
  
     }
  
  
     public void paint(Graphics g)
      {  
          try {       
  
            System.out.println("Before Rotation");
            g.drawPolygon(x, y, no_pts);
            matrixIdentity(tMatrix);
            System.out.println("Identity Matrix Created");
            rotation(60,10,10);
            System.out.println("Rotating");
  
            for(int a=0; a&lt;3;a++)
            {
                for(int c=0; c&lt;3;c++)
                {
                    System.out.print(tMatrix[a][c] + " ");
                }
                System.out.println();
            }
  
            for(int a=0; a&lt;3;a++)
            {
                System.out.println(x[a] + " " + y[a]);
            }
  
            transformPoints();
            System.out.println("After Rotation");
            g.drawPolygon(x, y, no_pts);
  
          }
          catch(Exception e){}
  
        }   
  
       void matrixIdentity(int[][] m)
      {int i,j;
      for(i=0;i&lt;3;i++)
      for(j=0;j&lt;3;j++)
      { if(i==j)
        { 
            m[i][j]=1;
        }
      else
          m[i][j]=0;
      }
      }    
  
       void transformPoints()
       { 
           int tmp;
           for(int a=0; a&lt;3;a++)
     {  
              tmp=tMatrix[0][0]*x[a]+ tMatrix[0][1]*y[a]+tMatrix[0][2];
  
              y[a]=tMatrix[1][0]*x[a]+tMatrix[1][1]*y[a]+tMatrix[1][2];
  
              x[a]=tmp;
          }
     }    
  
      void rotation(double degree,int rx,int ry)
      {   int a;
          a = (int) (degree * 3.14/180);
          tMatrix[0][0]= (int) Math.cos(a) ;
          tMatrix[0][1]= (int) -Math.sin(a) ;
          tMatrix[0][2]= (int) (rx*(1-Math.cos(a))+ ry*Math.sin(a));
          tMatrix[1][0]= (int) Math.sin(a) ;
          tMatrix[1][1]= (int) Math.cos(a);
          tMatrix[1][2]= (int) (ry*(1-Math.cos(a))-rx*Math.sin(a));        
      }
  }
  </code></pre>
  
  <p>It prints the original shape but does not print the rotated shape.</p>