UNB/ CS/ David Bremner/ teaching/ java/ Rotate.java
import ccj.*;

public class Rotate extends GraphicsApplet
{  public void run()
   {  double[][] rot = new double[3][3];
      double alpha = 5 * Math.PI / 180; /* 5 degrees */
      rot[0][0] = Math.cos(alpha);
      rot[0][1] = -Math.sin(alpha);
      rot[0][2] = 0;
      rot[1][0] = Math.sin(alpha);
      rot[1][1] = Math.cos(alpha);
      rot[1][2] = 0;
      rot[2][0] = 0;
      rot[2][1] = 0;
      rot[2][2] = 1;

      double[] v = new double[3];
      v[0] = 5; v[1] = 5; v[2] = 1;
      int i;
      for (i = 1; i <= 30; i++)
      {  v = vproduct(rot, v);
         new Point(v[0], v[1]).draw();
      }
   }

   public static double[] vproduct(double[][] a, double[] v)
   {  double[] r = new double[a.length];

      int i;
      for (i = 0; i < a.length; i++)
      {  if (a[i].length != v.length)
            throw new IllegalArgumentException();
         int k;
         double sum = 0;
         for (k = 0; k < v.length; k++)
            sum = sum + a[i][k] * v[k];
         r[i] = sum;
      }
      return r;
   }

}