Length of the transverse common tangent between the two non intersecting circles

07 Jun, 2022
Given two circles of given radii, having there centres a given distance apart, such that the circles don’t touch each other. The task is to find the length of the transverse common tangent between the circles.Examples:  
Input: r1 = 4, r2 = 6, d = 12
Output: 6.63325

Input: r1 = 7, r2 = 9, d = 21
Output: 13.6015
 
Approach:  
Let the radii of the circles be r1 & r2 respectively.Let the distance between the centers be d units.Draw a line O’R parallel to PQ,angle OPQ = angle RPQ = 90 deg angle O’QP = 90 deg { line joining the center of the circle to the point of contact makes an angle of 90 degree with the tangent }  angle RPQ + angle O’QP = 180 deg PR || O’QSince opposite sides are parallel and interior angles are 90, therefore O’PQR is a rectangle.O’Q = RP = r2 and PQ = O’RIn triangle OO’Rangle ORO’ = 90 deg By Pythagoras theorem, OR^2 + O’R^2 = OO’^2 O’R^2 = OO’^2 – OR^2 O’R^2 = d^2 – (r1+r2)^2 O’R^2 = √(d^2 – (r1+r2)^2)
Let the radii of the circles be r1 & r2 respectively.
Let the distance between the centers be d units.
Draw a line O’R parallel to PQ,
angle OPQ = angle RPQ = 90 deg angle O’QP = 90 deg { line joining the center of the circle to the point of contact makes an angle of 90 degree with the tangent }  
angle RPQ + angle O’QP = 180 deg PR || O’Q
Since opposite sides are parallel and interior angles are 90, therefore O’PQR is a rectangle.
O’Q = RP = r2 and PQ = O’R
In triangle OO’Rangle ORO’ = 90 deg By Pythagoras theorem, OR^2 + O’R^2 = OO’^2 O’R^2 = OO’^2 – OR^2 O’R^2 = d^2 – (r1+r2)^2 O’R^2 = √(d^2 – (r1+r2)^2)
 
C++
Java
Python3
C#
PHP
Javascript
// C++ program to find the length// of the transverse common tangent// between two circles which// do not touch each other #include <bits/stdc++.h>using namespace std; // Function to find the length// of the transverse common tangentvoid lengthOfTangent(double r1, double r2, double d){     cout << "The length of the transverse"         << " common tangent is "         << sqrt(pow(d, 2) - pow((r1 + r2), 2))         << endl;} // Driver codeint main(){    double r1 = 4, r2 = 6, d = 12;    lengthOfTangent(r1, r2, d);    return 0;}
// Java program to find the length// of the transverse common tangent// between two circles which// do not touch each otherclass GFG {     // Function to find the length    // of the transverse common tangent    static void lengthOfTangent(double r1,                                double r2, double d)    {         System.out.println("The length of the transverse"                           + " common tangent is "                           + Math.sqrt(Math.pow(d, 2)                                       - Math.pow((r1 + r2), 2)));    }     // Driver code    public static void main(String args[])    {        double r1 = 4, r2 = 6, d = 12;        lengthOfTangent(r1, r2, d);    }} // This code has been contributed by 29AjayKumar
# python 3 program to find the length# of the transverse common tangent# between two circles which# do not touch each otherfrom math import sqrt, pow # Function to find the length# of the transverse common tangentdef lengthOfTangent(r1, r2, d):    print("The length of the transverse",                     "common tangent is",          '{0:.6g}'.format(sqrt(pow(d, 2) -                                pow((r1 + r2), 2)))) # Driver codeif __name__ == '__main__':    r1 = 4    r2 = 6    d = 12    lengthOfTangent(r1, r2, d)     # This code is contributed by# Surendra_Gangwar
// C# program to find the length// of the transverse common tangent// between two circles which// do not touch each otherusing System; class GFG {    // Function to find the length    // of the transverse common tangent    static void lengthOfTangent(double r1,                                double r2, double d)    {         Console.WriteLine("The length of the transverse"                          + " common tangent is "                          + Math.Sqrt(Math.Pow(d, 2)                                      - Math.Pow((r1 + r2), 2)));    }     // Driver code    static public void Main()    {        double r1 = 4, r2 = 6, d = 12;        lengthOfTangent(r1, r2, d);    }} // This code has been contributed by ajit.
<?php// PHP program to find the length// of the transverse common tangent// between two circles which// do not touch each other // Function to find the length// of the transverse common tangentfunction lengthOfTangent($r1, $r2, $d){     echo "The length of the transverse common tangent is ",    sqrt(pow($d, 2) - pow(($r1 + $r2), 2)) ;} // Driver code$r1 = 4; $r2 = 6; $d = 12;lengthOfTangent($r1, $r2, $d); // This code is contributed by AnkitRai01?>
<script> // javascript program to find the length// of the transverse common tangent// between two circles which// do not touch each other  // Function to find the length// of the transverse common tangentfunction lengthOfTangent(r1,r2 , d){     document.write("The length of the transverse"                       + " common tangent is "                       + Math.sqrt(Math.pow(d, 2)                                   - Math.pow((r1 + r2), 2)));} // Driver code var r1 = 4, r2 = 6, d = 12;lengthOfTangent(r1, r2, d); // This code contributed by Princi Singh </script>
The length of the transverse common tangent is 6.63325
 
Time Complexity: O(1)
Auxiliary Space: O(1)
ankthon
29AjayKumar
SURENDRA_GANGWAR
jit_t
princi singh
souravkumar29
circle
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.