如何使多边形附着到3点钟位置的点

问题描述 投票:-2回答:1

我正在研究一个项目,我已经完成了大部分工作,但是我很难看到如何让坐标排成一行。我被卡住了,我不确定如何得到一个点,在3点钟,我被卡住了。我已经尝试过寻找示例,但我看到的只是多边形,不需要与任何内容进行对比。有帮助吗?

说明:假设n边正多边形以(0,0)为中心,其中一点位于3点钟位置,如图5.4所示。编写一个程序,提示用户输入边的数量,多边形的边界圆的半径,并显示多边形上的角点的坐标。

import java.util.Scanner;

public class Polygon {

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);
 System.out.print("Enter the number of sides: ");
 int sides = input.nextInt();

 System.out.print("Enter the radius of the bounding circle: ");
 double radius = input.nextDouble();
 input.close();

 System.out.println("The coordinates of the points on the polygon are");
 for (int i = 0; i < sides; i++) {

     double x = radius * java.lang.Math.sin(2.0 * java.lang.Math.PI / sides * i);
     double y = radius * java.lang.Math.cos(2.0 * java.lang.Math.PI / sides * i);
     System.out.print("(");
     System.out.printf("%.2f", x);
     System.out.print(" ");
     System.out.printf("%.2f",y);
     System.out.print(")");
     System.out.println();
     }

   }
}
java polygon radius
1个回答
1
投票

你需要切换你的sincos表达式。然后,多边形的第一个点将始终位于(radius, 0),即与3点钟位置对齐。

     double x = radius * java.lang.Math.cos(2.0 * java.lang.Math.PI / sides * i);
     double y = radius * java.lang.Math.sin(2.0 * java.lang.Math.PI / sides * i);
© www.soinside.com 2019 - 2024. All rights reserved.