这应该使用表达式绘制规则的多边形:
xk = R * cos((π/2 + 2*π*k) /N);
yk = R * sin((π/2 + 2*π*k) /N)
(N - number of angles, R - Circumscribed circle radius, 0 < k < N).
在这里我把N =4。不知道出什么问题了,但是它只能画直线。请发送帮助!
double piDrugich = 3.14/2;
double dwaPi = 6.28;
drawing(){
x = new int[4];
y = new int[4];
for(int i=0; i<4; i++) {
x[i] =300+R*(int)Math.cos((piDrugich + dwaPi*i)/4);
}
for(int i=0; i<4; i++) {
y[i] =150+R*(int)Math.sin((piDrugich + dwaPi*i)/4);
}
}
public void paintComponent(Graphics g) {
super.paintComponent(g);
P = new Polygon(x, y, 4);
g.drawPolygon(P);
}