0
我一直在使用下面的代碼來繪製一個旋轉的多邊形:Java的平局三角
public static void renderPoly(Graphics g, double cx, double cy, int sides, double radius, double rotation){
Graphics2D g2d = (Graphics2D) g;
double deltaAngle = (Math.PI * 2)/sides;
double angle;
double lastX = cx + radius * Math.cos(0 - rotation);
double lastY = cy + radius * Math.sin(0 - rotation);
for(int n = 1; n <= sides; n++){
angle = deltaAngle * n;
double x = cx + radius * Math.cos(angle - rotation);
double y = cx + radius * Math.cos(angle - rotation);
g2d.drawLine((int)lastX, (int)lastY, (int)x, (int)y);
lastX = x;
lastY = y;
};
};
不幸的是,這是沒有工作對我來說,當我把它叫做:
renderPoly(g, 15, 15, 3, 5, Math.toRadians(-90));
我的代碼出了什麼問題?謝謝。
您可能還想看看這個PolygonFactory類:http://sourceforge.net/p/tus/code/HEAD/tree/tjacobs/ui/shape/PolygonFactory.java – ControlAltDel 2014-09-24 02:05:44