转换Rectangle2D java

时间:2014-05-14 02:30:12

标签: java swing transform

我正在尝试通过特定的theta旋转Rectangle2D对象。但是我不能这样做,因为Rectangle2D的方法转换(AffineTransform)是未定义的。有关如何做到这一点的任何想法?感谢。

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;

1 个答案:

答案 0 :(得分:5)

由于Rectangle2DShape,您可能正在寻找AffineTransform方法createTransformedShape()。引用了一个完整的例子here