Ejemplo n.º 1
0
  /**
   * Rotate the polygon clockwise about a point by an arbritray angle.
   *
   * @param x X ordinate of point to rotate about
   * @param y Y ordinate of point to rotate about
   * @param angle Angle in radians
   */
  public void rotate(double x, double y, double angle) {
    double theta = -angle;

    for (Enumeration e = vertices(); e.hasMoreElements(); ) {
      Vector2D vertex = (Vector2D) e.nextElement();

      // translate to origin
      double tmpX = vertex.getX() - x;
      double tmpY = vertex.getY() - y;

      // rotate
      double sin = Math.sin(theta);
      double cos = Math.cos(theta);

      double newX = tmpX * cos - tmpY * sin;
      double newY = tmpX * sin + tmpY * cos;

      // translate back to old location
      newX += x;
      newY += y;

      // set teh point to be where we calculated it should be
      vertex.setXY(newX, newY);
    }

    flagModified();
  }