Sunday, February 15, 2009

triangle


















ZG
int width = 200;
int height = 200;
float[][] rotateMatrix = new float[2][2];

void setup()
{
  size (width,height);
  noLoop();
}

void draw()
{
  int x0, y0, x1, y1, x2, y2;
  x0 = int(random(width));
  y0 = int(random(height));
  x1 = int(random(width));
  y1 = int(random(height));
  x2 = int(random(width));
  y2 = int(random(height));
  for (float i =0; i <>
  {
  float rotateAngle = i * PI;
  rotation(x0, y0, x1, y1, x2, y2, rotateAngle);
  }
}

void rotation(int x0, int y0, int x1, int y1, int x2, int y2, float rotateAngle)
{
  buildMatrix(rotateAngle);
  
float[][] trianglePoints = {{x0, y0}, {x1, y1}, {x2, y2}};
  triangle(trianglePoints[0][0],trianglePoints[0][1],trianglePoints[1][0],trianglePoints[1][1],trianglePoints[2][0],trianglePoints[2][1]);
  
  trianglePoints = multiply(trianglePoints, rotateMatrix);
  triangle(trianglePoints[0][0],trianglePoints[0][1],trianglePoints[1][0],trianglePoints[1][1],trianglePoints[2][0],trianglePoints[2][1]);
  
  
}
float[][] multiply(float[][]a, float[][]b)
{
  float[][]c = new float[a.length][b[0].length];
  for (int i = 0; i <>
    for (int j = 0; j <>
      for (int k = 0; k <>
        c[i][j] += a[i][k] * b[k][j];
      }
    }
  }
  return c;
}
void buildMatrix(float rotateAngle)
{
  rotateMatrix[0][0] = cos(rotateAngle);
  rotateMatrix[0][1] = sin(rotateAngle);
  rotateMatrix[1][0] = -sin(rotateAngle);
  rotateMatrix[1][1] = cos(rotateAngle);
}

No comments:

Post a Comment