Problem

(Drag points) Draw a circle with three random points on the circle. Connect the points to...

(Drag points) Draw a circle with three random points on the circle. Connect the points to form a triangle. Display the angles in the triangle. Use the mouse to drag a point along the perimeter of the circle. As you drag it, the triangle and angles are redisplayed dynamically, as shown in Figure 1b. For computing angles in a triangle, see Listing 1.

FIGURE 1 (a) Exercise enables the user to drag vertices and display the angles dynamically. (b) Exercise enables the user to drag vertices along the circle and display the angles in the triangle dynamically.

LISTING 1 ComputeAngles.java

1 import java.util.Scanner;

2

3 public class ComputeAngles {

4 public static void main(String[] args) {

5 Scanner input = new Scanner(System.in);

6

7 // Prompt the user to enter three points

8 System.out.print("Enter three points: ");

9 double x1 = input.nextDouble();

10 double y1 = input.nextDouble();

11 double x2 = input.nextDouble();

12 double y2 = input.nextDouble();

13 double x3 = input.nextDouble();

14 double y3 = input.nextDouble();

15

16 // Compute three sides

17 double a = Math.sqrt((x2 - x3) * (x2 - x3)

18 + (y2 - y3) * (y2 - y3));

19 double b = Math.sqrt((x1 - x3) * (x1 - x3)

20 + (y1 - y3) * (y1 - y3));

21 double c = Math.sqrt((x1 - x2) * (x1 - x2)

22 + (y1 - y2) * (y1 - y2));

23

24 // Compute three angles

25 double A = Math.toDegrees(Math.acos((a * a - b * b - c * c)

26 / (-2 * b * c)));

27 double B = Math.toDegrees(Math.acos((b * b - a * a - c * c)

28 / (-2 * a * c)));

29 double C = Math.toDegrees(Math.acos((c * c - b * b - a * a)

30 / (-2 * a * b)));

31

32 // Display results

33 System.out.println("The three angles are " +

34 Math.round(A * 100) / 100.0 + " " +

35 Math.round(B * 100) / 100.0 + " " +

36 Math.round(C * 100) / 100.0);

37 }

38 }

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT