Java黑皮书课后题第4章:*4.7(顶点坐标)假设一个正五边形的中心位于(0,0),其中一个点位于0点位置。编写程序,提示用户输入正五边形外接圆的半径,显示p1到p5的5个坐标,保留两位小数
*4.7(頂點(diǎn)坐標(biāo))假設(shè)一個(gè)正五邊形的中心位于(0,0),其中一個(gè)點(diǎn)位于0點(diǎn)位置。編寫(xiě)程序,提示用戶輸入正五邊形外接圓的半徑,顯示p1到p5為5個(gè)坐標(biāo),保留兩位小數(shù)
- 題目
- 題目概述
- 運(yùn)行示例
- 破題
- 代碼
題目
題目概述
*4.7(頂點(diǎn)坐標(biāo))假設(shè)一個(gè)正五邊形的中心位于(0,0),其中一個(gè)點(diǎn)位于0點(diǎn)位置。編寫(xiě)程序,提示用戶輸入正五邊形外接圓的半徑,顯示p1到p5的5個(gè)坐標(biāo),保留兩位小數(shù)
運(yùn)行示例
Enter the radius of the bounding circle: 100.52
The coordinates of five points on the pentagon are
(95.60, 31.06)
(0.00, 100.52)
(-95.60, 31.06)
(-58.08, -81.32)
(59.08, -81.32)
破題
題目翻譯槽點(diǎn)很多,沒(méi)圖根本理解不了
翻譯一下題目:
有一個(gè)正五邊形中心在原點(diǎn),這個(gè)五邊形有個(gè)外接圓,五邊形的五個(gè)頂點(diǎn)在圓上(其中一個(gè)頂點(diǎn)p2在原點(diǎn)0點(diǎn)方向,p2左邊是p3、右邊是p1)
然后要通過(guò)console控制臺(tái)輸入的值(外接圓半徑),求出5個(gè)點(diǎn)的坐標(biāo)
代碼
import java.util.Scanner;public class Test4_7 {public static void main(String[] args) {// 獲取半徑Scanner input = new Scanner(System.in);System.out.println("Enter the radius of the bounding circle: ");double r = input.nextDouble();// 求頂點(diǎn)到x軸夾角的幾個(gè)特殊值double angle18 = Math.toRadians(90 - 360 / 5);double angle54 = Math.toRadians((2 * 360) / 5 - 90);// 求出5個(gè)頂點(diǎn)的x、y坐標(biāo)System.out.println(r * Math.cos(angle54)+" "+ r * Math.sin(angle54));double xp1 = r * Math.cos(angle18), yp1 = r * Math.sin(angle18);double xp2 = 0, yp2 = r;double xp3 = -r * Math.cos(angle18), yp3 = r * Math.sin(angle18);double xp4 = -r * Math.cos(angle54), yp4 = -r * Math.sin(angle54);double xp5 = r * Math.cos(angle54), yp5 = -r * Math.sin(angle54);// 輸出數(shù)據(jù)System.out.println("The coordinates of five points on the pentagon are");System.out.printf("(%.2f, %.2f)", xp1, yp1);System.out.printf("\n(%.2f, %.2f)", xp2, yp2);System.out.printf("\n(%.2f, %.2f)", xp3, yp3);System.out.printf("\n(%.2f, %.2f)", xp4, yp4);System.out.printf("\n(%.2f, %.2f)", xp5, yp5);} }總結(jié)
以上是生活随笔為你收集整理的Java黑皮书课后题第4章:*4.7(顶点坐标)假设一个正五边形的中心位于(0,0),其中一个点位于0点位置。编写程序,提示用户输入正五边形外接圆的半径,显示p1到p5的5个坐标,保留两位小数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java黑皮书课后题第4章:*4.6(图
- 下一篇: Java黑皮书课后题第4章:*4.8(给