Open In App

Length of the perpendicular bisector of the line joining the centers of two circles

Last Updated : 03 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Given are two circles whose radii are given, such that the smaller lies completely within the bigger circle, and they touch each other at one point. We have to find the length of the perpendicular bisector of the line joining the centres of the circles.
Examples: 
 

Input: r1 = 5, r2 = 3
Output: 9.79796

Input: r1 = 8, r2 = 4
Output: 15.4919

 

Approach
 

  • Let the two circles have center at A and B.The perpendicular bisector PQ, bisects the line at C
     
  • Let radius of bigger circle = r1 
    radius of smaller circle = r2 
     
  • so, AB = r1-r2
     
  • therefore, AC = (r1-r2)/2 
     
  • In, the figure, we see 
    PA = r1 
     
  • in triangle ACP
    PC^2 + AC^2 = PA^2 
    PC^2 = PA^2 – AC^2 
    PC^2 = r1^2 – (r1-r2)^2/4 
     
  • so, PQ = 2*√(r1^2 – (r1-r2)^2/4) 
     

 

Length of the perpendicular bisector = 2 * sqrt(r1^2 – (r1-r2)*(r1-r2)/4)

Below is the implementation of the above approach: 
 

C++




// C++ program to find the Length
// of the perpendicular bisector
// of the line joining the centers
// of two circles in which one lies
// completely inside touching the
// bigger circle at one point
 
#include <bits/stdc++.h>
using namespace std;
 
void lengperpbisect(double r1, double r2)
{
    double z = 2 * sqrt((r1 * r1)
                        - ((r1 - r2)
                           * (r1 - r2) / 4));
 
    cout << "The length of the "
         << "perpendicular bisector is "
         << z << endl;
}
 
// Driver code
int main()
{
    double r1 = 5, r2 = 3;
    lengperpbisect(r1, r2);
    return 0;
}


Java




// Java program to find the Length
// of the perpendicular bisector
// of the line joining the centers
// of two circles in which one lies
// completely inside touching the
// bigger circle at one point
 
class GFG {
     
static void lengperpbisect(double r1, double r2)
{
    double z = 2 * Math.sqrt((r1 * r1)
                        - ((r1 - r2)
                        * (r1 - r2) / 4));
 
    System.out.println("The length of the "
        + "perpendicular bisector is "
        + z );
}
 
// Driver code
public static void main(String[] args)
{
    double r1 = 5, r2 = 3;
    lengperpbisect(r1, r2);
}
}
 
// This code has been contributed by 29AjayKumar


Python3




     
# Python program to find the Length
# of the perpendicular bisector
# of the line joining the centers
# of two circles in which one lies
# completely inside touching the
# bigger circle at one point
 
def lengperpbisect(r1, r2):
    z = 2 * (((r1 * r1) - ((r1 - r2) * (r1 - r2) / 4))**(1/2));
 
    print("The length of the perpendicular bisector is ", z);
 
 
# Driver code
r1 = 5; r2 = 3;
lengperpbisect(r1, r2);
 
# This code contributed by PrinciRaj1992


C#




// C# program to find the Length
// of the perpendicular bisector
// of the line joining the centers
// of two circles in which one lies
// completely inside touching the
// bigger circle at one point
using System;
 
class GFG
{
     
static void lengperpbisect(double r1, double r2)
{
    double z = 2 * Math.Sqrt((r1 * r1)
                        - ((r1 - r2)
                        * (r1 - r2) / 4));
 
    Console.WriteLine("The length of the "
        + "perpendicular bisector is "
        + z );
}
 
// Driver code
public static void Main()
{
    double r1 = 5, r2 = 3;
    lengperpbisect(r1, r2);
}
}
 
// This code has been contributed by anuj_67..


Javascript




<script>
// javascript program to find the Length
// of the perpendicular bisector
// of the line joining the centers
// of two circles in which one lies
// completely inside touching the
// bigger circle at one point
 
function lengperpbisect(r1 , r2)
{
    var z = 2 * Math.sqrt((r1 * r1)
                        - ((r1 - r2)
                        * (r1 - r2) / 4));
 
    document.write("The length of the "
        + "perpendicular bisector is "
        + z.toFixed(5) );
}
 
// Driver code
 
var r1 = 5, r2 = 3;
lengperpbisect(r1, r2);
 
 
// This code is contributed by 29AjayKumar
</script>


Output: 

The length of the perpendicular bisector is 9.79796

 

Time Complexity: O(log(n)), since using inbuilt sqrt function

Auxiliary Space: O(1)



Similar Reads

Ratio of the distance between the centers of the circles and the point of intersection of two direct common tangents to the circles
Given two circles of given radii, such that the circles don’t touch each other, the task is 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. Examples: Input: r1 = 4, r2 = 6 Output: 2:3 Input: r1 = 22, r2 = 43 Output: 22:43 Approach: Let the radii of the
5 min read
Ratio of the distance between the centers of the circles and the point of intersection of two transverse common tangents to the circles
Given two circles, of given radii, such that the circles don’t touch each other. The task is to find the ratio of the distance between the centres of the circles and the point of intersection of two transverse common tangents to the circles.Examples: Input :r1 = 4, r2 = 8 Output :1:2 Input :r1 = 5, r2 = 13 Output :5:13 Approach: Let the radii of th
5 min read
Equation of a straight line with perpendicular distance D from origin and an angle A between the perpendicular from origin and x-axis
Given two integers D and A representing the perpendicular distance from the origin to a straight line and the angle made by the perpendicular with the positive x-axis respectively, the task is to find the equation of the straight line. Examples: Input: D = 10, A = 30 degreesOutput: 0.87x +0.50y = 10 Input: D = 12, A = 45 degreesOutput: 0.71x +0.71y
5 min read
Distance between centers of two intersecting circles if the radii and common chord length is given
Given are two circles, with given radii, which intersect each other and have a common chord. The length of the common chord is given. The task is to find the distance between the center of the two circles. Examples: Input: r1 = 24, r2 = 37, x = 40 Output: 44 Input: r1 = 14, r2 = 7, x = 10 Output: 17 Approach: let the length of common chord AB = xLe
5 min read
Check if two circles intersect such that the third circle passes through their points of intersections and centers
Given centres and the radii of three circles A, B, and C in the form of {X, Y, R}, where (X, Y) is the centre of the circle and R is the radius of that circle. The task is to check if any two circles intersect such that the third circle passes through the intersecting points and the centres of the two circles. If found to be true, then print "Yes".
9 min read
Number of common tangents between two circles if their centers and radius is given
Given two circles with a given radius and centers. The task is to find the number of common tangents between these circles.Examples: Input: x1 = -10, y1 = 8, x2 = 14, y2 = -24, r1 = 30, r2 = 10 Output: 3 Input: x1 = 40, y1 = 8, x2 = 14, y2 = 54, r1 = 39, r2 = 51 Output: 2 Approach: First of all we will check whether the circles touch each other ext
7 min read
Angle of intersection of two circles having their centers D distance apart
Given two positive integers R1 and R2 representing the radius of two intersecting circles having a distance D between their centers, the task is to find the cosine of the angle of intersection between the two circles. Examples: Input: R1 = 3, R2 = 4, D = 5Output: 0 Input: R1 = 7, R2 = 3, D = 6Output: 0.52381 Approach: The given problem can be solve
4 min read
Find the radius of the circles which are lined in a row, and distance between the centers of first and last circle is given
Given here are n circles which touch each other externally, and are lined up in a row. The distance between the centers of the first and last circle is given. The circles have a radius of equal length. The task is to find the radius of each circle. Examples: Input: d = 42, n = 4 Output: The radius of each circle is 7 Input: d = 64, n = 5 Output: Th
3 min read
Maximum possible intersection by moving centers of line segments
Given three points on the X-axis which denotes the center of three line segments. The length of the line segment is also given as L. The task is to move the center of the given line segments by a distance of K to maximize the length of intersection between the three lines. Examples: Input: c1 = 1, c2 = 2, c3 = 3, L = 1, K = 0 Output: 0 Since, no ce
5 min read
Slope of perpendicular to line
You are given the slope of one line (m1) and you have to find the slope of another line which is perpendicular to the given line. Examples: Input : 5 Output : Slope of perpendicular line is : -0.20 Input : 4 Output : Slope of perpendicular line is : -0.25 Suppose we are given two perpendicular line segments AB and CD. The slope of AB is m1 and line
3 min read
Article Tags :
Practice Tags :