Dados dos círculos, de radios dados, que se tocan externamente. La tarea es encontrar la longitud de la tangente común directa entre los círculos.
Ejemplos:
Input: r1 = 5, r2 = 9 Output: 13.4164 Input: r1 = 11, r2 = 13 Output: 23.9165
Acercarse
- Sean los radios r1 y r2 respectivamente.
- Dibuja una línea O paralela a PQ
- ángulo OPQ = 90 grados
ángulo O’QP = 90 grados
{ la línea que une el centro del círculo con el punto de contacto forma un ángulo de 90 grados con la tangente } - ángulo OPQ + ángulo O’QP = 180
OP || código QR - Dado que los lados opuestos son paralelos y los ángulos interiores son 90, entonces OPQR es un rectángulo.
- Entonces OP = QR = r1 y PQ = OR = r1+r2
- En el triángulo OO’R
ángulo ORO’ = 90
Por el teorema de Pitágoras
OR^2 + O’R^2 = OO’^2
OO’^2 = (r1+r2)^2 + (r1-r2)^2 - Entonces, OO’ = 2√(r1*r2)
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to find the length of the direct // common tangent between two circles // which externally touch each other #include <bits/stdc++.h> using namespace std; // Function to find the length // of the direct common tangent void lengtang(double r1, double r2) { cout << "The length of the " << "direct common tangent is " << 2 * sqrt(r1 * r2) << endl; } // Driver code int main() { double r1 = 5, r2 = 9; lengtang(r1, r2); return 0; }
Java
// Java program to find the length of the direct // common tangent between two circles // which externally touch each other class GFG { // Function to find the length // of the direct common tangent static void lengtang(double r1, double r2) { System.out.println("The length of the " + "direct common tangent is " + (2 * Math.sqrt(r1 * r2))); } // Driver code public static void main(String[] args) { double r1 = 5, r2 = 9; lengtang(r1, r2); } } // This code contributed by Rajput-Ji
Python3
# Python3 program to find the length # of the direct common tangent # between two circles which # externally touch each other # Function to find the length # of the direct common tangent def lengtang(r1, r2): print("The length of the direct", "common tangent is", 2 * (r1 * r2)**(1 / 2)); # Driver code r1 = 5; r2 = 9; lengtang(r1, r2); # This code contributed # by PrinciRaj1992
C#
// C# program to find the length of the direct // common tangent between two circles // which externally touch each other using System; class GFG { // Function to find the length // of the direct common tangent static void lengtang(double r1, double r2) { Console.WriteLine("The length of the " + "direct common tangent is " + (2 * Math.Sqrt(r1 * r2))); } // Driver code static public void Main () { double r1 = 5, r2 = 9; lengtang(r1, r2); } } // This code contributed by ajit.
PHP
<?php // PHP program to find the length of the direct // common tangent between two circles // which externally touch each other // Function to find the length // of the direct common tangent function lengtang($r1, $r2) { echo "The length of the " , "direct common tangent is " , 2 * sqrt($r1 * $r2) ; } // Driver code $r1 = 5; $r2 = 9; lengtang($r1, $r2); // This code is contributed by AnkitRai01 ?>
Javascript
<script> // javascript program to find the length of the direct // common tangent between two circles // which externally touch each other // Function to find the length // of the direct common tangent function lengtang(r1 , r2) { document.write("The length of the " + "direct common tangent is " + (2 * Math.sqrt(r1 * r2)).toFixed(5)); } // Driver code var r1 = 5, r2 = 9; lengtang(r1, r2); // This code contributed by Princi Singh </script>
Producción:
The length of the direct common tangent is 13.4164
Complejidad de tiempo: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA