Distance between two centers of circles: In the previous article, we have discussed about 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
In this article we are going to see how to find distance between centers of two intersecting circles if the radius and common chord length is given by using Java programming language.
Java Program to Find Distance between Centers of Two Intersecting Circles if the Radii and Common Chord Length is Given
Before Jumping into the program directly let’s see how to Find Distance between centers of two intersecting circles if the radii and common chord length is given.
Suppose there are 2 circles named C1, C2 having radius r1, r2(given) & centers P,Q respectively
Both the circle have a common chord RS (given)
Now, you need to find the distance between the center of the two circles.
From the figure, OP is perpendicular RS
RO = OS (perpendicular bisector)
RO = RS/2 (Since, RO+OS = RS)
In triangle ROP, (using Pythagoras theorem)
H2 = P2 + B2
RP2 = PO2+ RO2
r22 = PO2 + (RS/2)2
PO2 = r22 – (RS/2)2
In triangle ROO (using Pythagoras theorem)
H2 = P2 + B2
RQ2 = QO2+ RO2
r12 = QO2 + (RS/2)2
QO2 = r12 – (RS/2)2
From the figure, QP = QO + OP
OP = √( r12 – (RS/2)2) + √(r22 – (RS/2)2)
Distance between the centers = √( r12 – (RS/2)2) + √(r22 – (RS/2)2)
Example:
R1 = 20
R2 = 10
AB = 7
PO = √( R12 – (AB/2)2) + √(R22 – (AB/2)2
=29.0588
Let’s see different ways to find distance between centers of two intersecting circles if the radius and common chord length is given.
Method-1: Java Program to Find Distance between Centers of Two Intersecting Circles if the Radius and Common Chord Length is Given 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 C1.
- Declare an double variable say ‘R2’ and assign the value to it, which holds the radius of the circle C2.
- Declare an double variable say ‘AB’ and assign the value to it, which holds the length of the common chord.
- Find the distance between 2 centers I.e OP using the formula √( R12 – (AB/2)2) + √(R22 – (AB/2)2)
- Print the result.
Program:
import java.io.*; class Main { public static void main(String [] args) { double R1 = 20; double R2 = 10; double AB = 7; // formula to find distance between center of 2 circles double D = Math.sqrt( R1*R1 - (AB/2)*(AB/2)) + Math.sqrt( R2*R2 - (AB/2)*(AB/2)) ; System.out.println("The distance between 2 centers is " + D); } }
Output: The distance between 2 centers is 29.058865665112812
Method-2: Java Program to Find Distance between Centers of Two Intersecting Circles if the Radius and Common Chord Length is Given By Using User Input Value
Approach:
- Declare an double variable say ‘R1’ which holds the radius of the circle C1.
- Declare an double variable say ‘R2’ which holds the radius of the circle C2.
- Declare an double variable say ‘AB’ which holds the length of the common chord.
- Then we will take the value of “R1”, “R2”, “AB”as user input using scanner class.
- Find the distance between 2 centers I.e OP using the formula √( R12 – (AB/2)2) + √(R22 – (AB/2)2)
- 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 length of the common chord of 2 circles"); double AB = s.nextDouble(); // formula to find distance between center of 2 circles double D = Math.sqrt( R1*R1 - (AB/2)*(AB/2)) + Math.sqrt( R2*R2 - (AB/2)*(AB/2)) ; System.out.println("The distance between 2 centers is " + D); } }
Output: Enter the radius of the circle C1 20 Enter the radius of the circle C2 10 Enter the length of the common chord of 2 circles 7 The distance between 2 centers is 29.058865665112812
Interested in programming and want to excel in it by choosing the short ways. Then, practicing with the available Java Program list is mandatory.
Related Java Programs:
- 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
- Java Program to Find Length of the Chord of the Circle whose Radius and the Angle Subtended at the Center by the Chord is Given
- Java Program to Find the Side of the Squares Which are Inclined Diagonally and Lined in a Row