【问题标题】:How can I find the coordinates of the circumference of a circle that rotates around the circumference of another circle?如何找到围绕另一个圆的圆周旋转的圆的圆周坐标?
【发布时间】:2017-06-24 01:46:32
【问题描述】:
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;
    }
}

【问题讨论】:

    标签: java user-interface geometry trigonometry


    【解决方案1】:

    在进入下一个点之前,你需要把你的圈子跑得筋疲力尽。所以你需要一个嵌套循环:

    double degAng = 0;
    double newDegAng = 0;
    double newRadius = 25;
    double radius = 150;
    double x, y, radAng, newX, newY, newRadAng;
    while ( degAng<360 ) {
        radAng = ( degAng * Math.PI ) / 180;
        x = centerX + radius * Math.cos ( radAng );
        y = centerY + radius * Math.sin ( radAng );
    
        newDegAng = 0;
        while ( newDegAng>-360 ) {
          newRadAng = (newDegAng * Math.PI) / 180;
          newX =  x - newRadius * Math.cos (newRadAng);
          newY =  y - newRadius * Math.sin (newRadAng);
          drawPoint ( (int) newX, (int) newY);
          newDegAng -= 0.45;
        }
    
        drawPoint( (int) x, (int) y );
        degAng += 0.45;
    }
    

    这会创建一个像这样的漂亮图片

    这会绘制所有的圆圈,因此它可以有效地创建一个管子。

    【讨论】:

      猜你喜欢
      • 2021-07-30
      • 2021-06-24
      • 2019-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      相关资源
      最近更新 更多