gpt4 book ai didi

java - 使用仿射变换旋转多边形

转载 作者:行者123 更新时间:2023-12-01 18:51:34 31 4
gpt4 key购买 nike

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

最佳答案

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

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());

关于java - 使用仿射变换旋转多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15736230/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com