1

I am trying to rotate a Rectangle2D object by a particular theta. But I cannot do this because the method transform(AffineTransform) is undefined for Rectangle2D. Any thoughts on how to do this? Thanks.

Rectangle2D.Double currentVehic = new Rectangle2D.Double(bottomLeft[0], bottomLeft[1],vehicWidth, vehicHeight);
    // Rotate the vehicle perimeter about its center
    AffineTransform rotate = new AffineTransform();
    //Rectangle2D rotatedVehic = AffineTransform.getRotateInstance(theta,x,y);
    rotate.setToRotation(theta, x, y);
    currentVehic.transform(rotate);

    return currentVehic;
user3014093
  • 389
  • 2
  • 5
  • 20

1 Answers1

6

Because a Rectangle2D is a Shape, you may be looking for the AffineTransform method createTransformedShape(). A complete example is examined here, and another is cited here.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045