我使用這個函數(shù)來創(chuàng)建一個十二邊形:private void getPoints(int x0, int y0,int r,int noOfDividingPoints){ double angle1 = 1; x = new int[noOfDividingPoints]; y = new int[noOfDividingPoints]; for(int i = 0 ; i < noOfDividingPoints ;i++) { angle1 = i * (360/noOfDividingPoints); x[i] = (int) Math.round(x0 + r * Math.cos(Math.toRadians(angle1))); y[i] = (int) Math.round(y0 + r * Math.sin(Math.toRadians(angle1))); }}然后我圍繞一個中心旋轉(zhuǎn)所有點:for (int i = 0; i < SLICES; i++) { int x1 = x[i] - center.x; int y1 = y[i] - center.y; int x2 = (int) Math.round(x1 * Math.cos(radian) - y1 * Math.sin(radian)); int y2 = (int) Math.round(x1 * Math.sin(radian) + y1 * Math.cos(radian)); x[i] = x2 + center.x; y[i] = y2 + center.y;}有了這個,我終于畫了線: for (int i = 0; i < SLICES; i++) { g.drawLine(center.x, center.y, x[i], y[i]); if (i != 0 ) { g.drawLine(x[i-1], y[i-1], x[i], y[i]); } else { g.drawLine(x[i], y[i], x[x.length-1], y[x.length-1]); } }問題:十二邊形旋轉(zhuǎn),但旋轉(zhuǎn)會使頂點變形,使形狀略微不規(guī)則;它在旋轉(zhuǎn)過程中發(fā)生變化:這是因為 Math.round() 完成了從 double 到 int 的轉(zhuǎn)換。不使用 Math.round() 十二邊形折疊到中心。如何在不改變形狀的情況下使用 int 值?我必須使用雙打嗎?
添加回答
舉報
0/150
提交
取消