0

我目前正在尝试使用仿射变换类旋转多边形。使用旋转方法,多边形的图形表示会更新,但多边形的边界框不会更新。除了更新它的坐标之外,如何旋转多边形?

4

1 回答 1

4

创建一个新形状,而不是在绘制多边形时只旋转多边形。例如:

Polygon shape = new Polygon();
shape.addPoint(...);
....
Rectangle bounds = shape.getBounds();
AffineTransform transform = new AffineTransform();
transform.rotate(Math.toRadians(angle), bounds.width / 2, bounds.height / 2);

Path2D path = (shape instanceof Path2D) ? (Path2D)shape : new GeneralPath(shape);
Shape rotated = path.createTransformedShape( transform );
System.out.println(rotated.getBounds());
于 2013-04-01T00:46:50.257 回答