In the previous article, we have discussed about Java Program to Find Interior and Exterior Angle of Regular Polygon when Number of Sides of Polygon is Given
In this article we are going to see how to find angle of intersection of two circles having their centers D
distance apart by using Java programming language.
Java Program to Find Angle of Intersection of Two Circles Having Their Centers D Distance Apart
Suppose there are two circles say Circle1
and Circle2
intersecting each-other.
Both circles are having radius R1
and R2
respectively.
Having distance D
from the center A
and B
Now, we need to find the angle of intersection of the 2 circles.
In triangle AOB
by using Pythagoras theorem
AOB = (R12 + R22 – D2) / (2 * R1 * R2)
Example:
R1 = 3 R2 = 4 D = 5 Cos a = (R1*R1 +R2*R2-D*D)/(2*R1*R2) = 25/24 = 0
Let’s see different ways to find angle of intersection of two circles having their centers D
distance apart.
Method-1: Java Program to Find Angle of Intersection of Two Circles Having Their Centers D Distance Apart By Using Static Input Value
Approach:
- Declare an double variable say ‘R1’ and assign the value to it, which holds the radius of the circle Circle1.
- Declare an double variable say ‘R2’ and assign the value to it, which holds the radius of the circle Circle2.
- Declare an double variable say ‘D’ and assign the value to it, which holds the distance between the centers of 2 circles.
- Find the intersection angle using the formula Cos a = (R12 +R22-D2)/(2*R1*R2)
- Print the result
Program:
import java.io.*; class Main { public static void main(String [] args) { double R1 = 3; double R2 = 4; double D = 5; // formula to find angle of intersection double a = (R1*R1 +R2*R2-D*D)/(2*R1*R2); System.out.println("The angle of intersection of 2 circle is " + a + " rad"); } }
Output: The angle of intersection of 2 circle is 0.0 rad
Method-2: Java Program to Find Angle of Intersection of Two Circles Having Their Centers D Distance Apart By Using User Input Value
Approach:
- Declare an double variable say ‘R1’ which holds the radius of the circle Circle1.
- Declare an double variable say ‘R2’ which holds the radius of the circle Circle2.
- Declare an double variable say ‘D’ which holds the distance between the centers of 2 circles.
- Then we will take the value of “R1”, “R2”, “D” as user input using scanner class.
- Find the intersection angle using the formula Cos a = (R12 +R22-D2)/(2*R1*R2)
- Print the result.
Program:
import java.io.*; import java.util.Scanner; class Main { public static void main(String [] args) { // scanner class obj ref Scanner s = new Scanner(System.in); System.out.println("Enter the radius of the circle C1"); // to take user input value double R1 = s.nextDouble(); System.out.println("Enter the radius of the circle C2"); double R2 = s.nextDouble(); System.out.println("Enter the distance between 2 centers"); double D = s.nextDouble(); // formula to find angle of intersection double a = (R1*R1 +R2*R2-D*D)/(2*R1*R2); System.out.println("The angle of intersection of 2 circle is " + a + " rad"); } }
Output: Enter the radius of the circle C1 8 Enter the radius of the circle C2 6 Enter the distance between 2 centers 10 The angle of intersection of 2 circle is 0.0 rad
Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.
Related Java Programs:
- Java Program to Find Ratio of the distance between the Centers of the Circles and the Point of Intersection of Two Direct Common Tangents to the Circles
- Java Program to Find Distance between Centers of Two Intersecting Circles if the Radius and Common Chord Length is Given
- Java Program to Find Length of the Chord of the Circle if Length of Another Chord Which is Equally Inclined through the Diameter is Given
- Java Program to Find Longest Chord of Circle When Radius is Given