本文介绍了转换Rectangle2D java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;


推荐答案

因为 Rectangle2D Shape ,您可能正在寻找 AffineTransform 方法。 引用了一个完整的示例。

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

这篇关于转换Rectangle2D java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 05:53