我发现了其他问题,询问如何做到这一点,但我没有让他们中的任何一个工作。我正在尝试编写一种方法,将多边形围绕它的中心旋转几度。我当前的代码使它在移动度数时从屏幕上消失。
public void rotate(double angle) {
AffineTransform at = new AffineTransform();
int xCoords [] = {(int)line1.getX1(), (int)line2.getX1(), (int)line3.getX1()};
int yCoords [] = {(int)line1.getY1(), (int)line2.getY1(), (int)line3.getY1()};
Polygon polygon = new Polygon(xCoords, yCoords, 3);
at.rotate(Math.toRadians(angle), getX(), getY());
for (int i = 0; i < polygon.npoints; i++){
Point p = new Point(polygon.xpoints[i], polygon.ypoints[i]);
at.transform(p, p);
//System.out.println(p.x);
//System.out.println(p.y);
poly.addPoint(p.x, p.y);
}
setA(poly.xpoints[1], poly.ypoints[1]);
setB(poly.xpoints[2], poly.ypoints[2]);
setC(poly.xpoints[3], poly.ypoints[3]);
}
编辑:包含尝试