【发布时间】:2013-04-01 00:42:31
【问题描述】:
我目前正在尝试使用仿射变换类旋转多边形。使用旋转方法,多边形的图形表示会更新,但多边形的边界框不会更新。除了更新它的坐标之外,我如何旋转多边形?
【问题讨论】:
-
多边形的“边界框”是什么意思?您是否将其存储为多边形的一部分?
我目前正在尝试使用仿射变换类旋转多边形。使用旋转方法,多边形的图形表示会更新,但多边形的边界框不会更新。除了更新它的坐标之外,我如何旋转多边形?
【问题讨论】:
创建一个新形状,而不是在绘制多边形时只旋转多边形。例如:
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());
【讨论】: