接下來我用程式來實現,程式在座標的計算上與數學常用的座標不太一樣。
//半徑 int r = 150; //座標的矩陣 slidepoint = new int[360][2]; //圓心位址 int x0 = 225; int y0 = 225; //計算 for (int i = 1; i < 361; i++) { int x1 = (int) (x0 + r * Math.cos(Math.toRadians(i))); int y1 = (int) (y0 + r * Math.sin(Math.toRadians(i))); slidepoint[360 - i][0] = x1; slidepoint[360 - i][1] = y1; //draw angle string if (i % 10 ==0) g.drawString(String.valueOf(i), x1, y1); }
我先用swing做個示範,每隔10度畫出角度在座標上
你會發現跟我們習慣的角度好像方向不同,我們做個轉換
class DrawPane extends JPanel { public void paintComponent(Graphics g) { //畫大圓 g.drawOval(0, 0, 450, 450); //大圓 int r = 150; //座標的矩陣 slidepoint = new int[360][2]; //圓心位址 int x0 = 225; int y0 = 225; //計算 for (int i = 1; i < 361; i++) { int x1 = (int) (x0 + r * Math.cos(Math.toRadians(i))); int y1 = (int) (y0 + r * Math.sin(Math.toRadians(i))); slidepoint[360 - i][0] = x1; slidepoint[360 - i][1] = y1; } //轉換 for (int i = 0; i < 360; i++) { int x1 = slidepoint[i][0]; int y1 = slidepoint[i][1]; //繪圓 if (i%10==0) g.drawString(String.valueOf(i), x1, y1); } } }
沒有留言:
張貼留言