user3014093
user3014093

Reputation: 409

transforming Rectangle2D java

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;

Upvotes: 1

Views: 2504

Answers (1)

trashgod
trashgod

Reputation: 205785

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.

Upvotes: 6

Related Questions