1
public static void drawSpiral(Display panel) {
int centerX = panel.getWidth()/2;
int centerY = panel.getHeight()/2;
double degAng = 270;
double radius = 150;
double x, y, radAng;
while (true) {
radAng = (degAng * Math.PI)/180;
x = centerX + radius * Math.cos (radAng);
y = centerY + radius * Math.sin (radAng);
panel.drawNextPoint ((int) x, (int) y);
degAng += 0.45;
}
}
我想創建一個使用簡單的GUI繪製的方法。上面的方法繪製了從頂部開始的半徑爲150的簡單圓的座標。我試圖畫出一個使用該方法給出的點作爲中心點的圓。如何找到圍繞另一個圓的圓周旋轉的圓的圓周座標?
這是我最近試過的,它只給了我一個橢圓!
public static void drawCircle(Display panel) {
int centerX = panel.getWidth()/2;
int centerY = panel.getHeight()/2;
double degAng = 270;
double newDegAng = 0;
double newRadius = 25;
double radius = 150;
double x, y, radAng, newX, newY, newRadAng;
while (true) {
radAng = (degAng * Math.PI)/180;
x = centerX + radius * Math.cos (radAng);
y = centerY + radius * Math.sin (radAng);
newRadAng = (newDegAng * Math.PI)/180;
newX = x - newRadius * Math.cos (newRadAng);
newY = y - newRadius * Math.sin (newRadAng);
panel.drawNextPoint ((int) newX, (int) newY);
degAng += 0.45;
newDegAng -= 0.45;
}
}