|
| 1 | +/*(Corner point coordinates) Suppose a pentagon is centered at (0, 0) with one point |
| 2 | +at the 0 o’clock position, as shown in Figure 4.7c. Write a program that prompts |
| 3 | +the user to enter the radius of the bounding circle of a pentagon and displays the |
| 4 | +coordinates of the five corner points on the pentagon. Here is a sample run: |
| 5 | + |
| 6 | +Enter the radius of the bounding circle: 100 |
| 7 | +The coordinates of five points on the pentagon are |
| 8 | +(95.1057, 30.9017) |
| 9 | +(0.000132679, 100) |
| 10 | +(-95.1056, 30.9019) |
| 11 | +(-58.7788, -80.9015) |
| 12 | +(58.7782, -80.902) |
| 13 | + |
| 14 | + */ |
| 15 | + |
| 16 | +import java.util.Scanner; |
| 17 | + |
| 18 | +public class Exercise_04_07 { |
| 19 | + public static void main(String[] args) { |
| 20 | + Scanner input = new Scanner(System.in); |
| 21 | + |
| 22 | + System.out.print("Enter the radius of the bounding circle: "); |
| 23 | + double radius = input.nextDouble(); |
| 24 | + |
| 25 | + // Starts with 18 degrees, 360 divided by 5 is 72 degrees according to sample |
| 26 | + |
| 27 | + |
| 28 | + double angleP1 = Math.toRadians(18); |
| 29 | + double angleP2 = Math.toRadians(18 + 72); |
| 30 | + double angleP3 = Math.toRadians(18 + 72 * 2); |
| 31 | + double angleP4 = Math.toRadians(18 + 72 * 3); |
| 32 | + double angleP5 = Math.toRadians(18 + 72 * 4); |
| 33 | + |
| 34 | + double x1 = radius * Math.cos(angleP1); |
| 35 | + double y1 = radius * Math.sin(angleP1); |
| 36 | + double x2 = radius * Math.cos(angleP2); |
| 37 | + double y2 = radius * Math.sin(angleP2); |
| 38 | + double x3 = radius * Math.cos(angleP3); |
| 39 | + double y3 = radius * Math.sin(angleP3); |
| 40 | + double x4 = radius * Math.cos(angleP4); |
| 41 | + double y4 = radius * Math.sin(angleP4); |
| 42 | + double x5 = radius * Math.cos(angleP5); |
| 43 | + double y5 = radius * Math.sin(angleP5); |
| 44 | + |
| 45 | + System.out.println("The coordinates of five points on the pentagon are "); |
| 46 | + System.out.println("(" + x1 + "," + y1 + ")"); |
| 47 | + System.out.println("(" + x2 + "," + y2 + ")"); |
| 48 | + System.out.println("(" + x3 + "," + y3 + ")"); |
| 49 | + System.out.println("(" + x4 + "," + y4 + ")"); |
| 50 | + System.out.println("(" + x5 + "," + y5 + ")"); |
| 51 | + } |
| 52 | + |
| 53 | +} |