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 the previous article, we have discussed about Java Program to Find Angle of Intersection of Two Circles Having Their Centers D Distance Apart

In this article we are going to see how 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 by using Java programming language.

Explanation:

Suppose there are 2 circles named Circle1 and Circle2  which do not touch to each other with center Q and R, radius R1 and R2 respectively.

Now, we need to find the 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 Ratio of the Distance between the Centers of the Circles and the Point of Intersection of Two Direct Common Tangents to the Circles

Both the circles are having two direct common tangents where P is the point of intersection of both tangents.

The point of contact of the tangents with the circles Circle1 and Circle2 are at A and B

In the triangles PQA and PRB

angle QAP = angle RBP = 90 deg (As angle between the line joining center of circle and to point of contact with the tangent is 90 degree)

angle APQ = angle BPR

angle AQP = angle BRP (As AQ and BR both are parallel to each other)
as all the angles are same, triangles PQA & PRB are similar

So, from above it is clear both triangle PQA and PRB are having similarity.

QP/RP = QA/RB = r1/r2

Example:

R1 = 12
R2 = 8
Ratio = 12 : 8 = 3 : 2

Let’s see different ways to solve it.

Method-1: 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 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 with center Q.
  • Declare an double variable say ‘r2’ and assign the value to it, which holds the radius of the circle with center R.
  • Find the ratio using the formula r1 / GCD(r1, r2) : r2 / GCD(r1, r2)
  • Print the result.

Program:

import java.io.*;
class Main
{
    public static void main(String [] args)
    {
        double R1 = 20;
        double R2 =  10;   
        int gcd = 1; 
        for (int i = 1; i<=R1 && i<=R2; i++)
    	{
    		if(R1%i==0 && R2%i==0)
    			gcd = i;
    	}
        int res1 = (int)R1/gcd;
        int res2 = (int)R2/gcd;
        System.out.println("The ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles is " + res1+ " : " + res2);
    }
}
Output:

The ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles is 2 : 1

Method-2: 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 By Using User Input Value

Approach:

  • Declare an double variable say ‘r1’ which holds the radius of the circle Q.
  • Declare an double variable say ‘r2’ which holds the radius of the circle with center R.
  • Then we will take the value of “r1”, “r2” as user input using scanner class.
  • Find the ratio using the formula r1 / GCD(r1, r2) : r2 / GCD(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();                     
        int gcd = 1; 
        for (int i = 1; i<=R1 && i<=R2; i++)
    	{
    		if(R1%i==0 && R2%i==0)
    			gcd = i;
    	}
        int res1 = (int)R1/gcd;
        int res2 = (int)R2/gcd;
        System.out.println("The ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles is " + res1+ " : " + res2);

    }
}
Output:

Enter the radius of the circle C1
10
Enter the radius of the circle C2
8
The ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles is 5 : 4

Practice Java programming from home without using any fancy software just by tapping on this Simple Java Programs for Beginners tutorial.

Related Java Programs: