Se dan dos círculos, con radios dados, que se cortan entre sí y tienen una cuerda común. Se da la longitud de la cuerda común. La tarea es encontrar la distancia entre el centro de los dos círculos. Ejemplos:
Input: r1 = 24, r2 = 37, x = 40 Output: 44 Input: r1 = 14, r2 = 7, x = 10 Output: 17
- sea la longitud de la cuerda común AB = x
- Sea el radio de la circunferencia de centro O OA = r2
- El radio del círculo con centro P es AP = r1
- De la figura, OP es perpendicular AB AC = CB AC = x/2 (Ya que AB = x)
- En el triángulo ACP , AP^2 = PC^2+ AC^2 [Por el teorema de Pitágoras] r1^2 = PC^2 + (x/2)^2 PC^2 = r1^2 – x^2/4
- Considere el triángulo ACO r2^2 = OC^2+ AC^2 [Por el teorema de Pitágoras] r2^2 = OC^2+ (x/2)^2 OC^2 = r2^2 – x^2/4
- De la figura, OP = OC+ PC OP = √( r1^2 – x^2/4 ) + √(r2^2 – x^2/4)
Distancia entre los centros = sqrt((radio de un círculo)^2 – (la mitad de la longitud de la cuerda común)^2) + sqrt((radio del segundo círculo)^2 – (la mitad de la longitud de la cuerda común) acorde )^2)
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program to find // the distance between centers // of two intersecting circles // if the radii and common chord length is given #include <bits/stdc++.h> using namespace std; void distcenter(int r1, int r2, int x) { int z = sqrt((r1 * r1) - (x / 2 * x / 2)) + sqrt((r2 * r2) - (x / 2 * x / 2)); cout << "distance between the" << " centers is " << z << endl; } // Driver code int main() { int r1 = 24, r2 = 37, x = 40; distcenter(r1, r2, x); return 0; }
Java
// Java program to find // the distance between centers // of two intersecting circles // if the radii and common chord length is given import java.lang.Math; import java.io.*; class GFG { static double distcenter(int r1, int r2, int x) { double z = (Math.sqrt((r1 * r1) - (x / 2 * x / 2))) + (Math.sqrt((r2 * r2) - (x / 2 * x / 2))); System.out.println ("distance between the" + " centers is "+ (int)z ); return 0; } // Driver code public static void main (String[] args) { int r1 = 24, r2 = 37, x = 40; distcenter(r1, r2, x); } } // This code is contributed by jit_t.
Python3
# Python program to find # the distance between centers # of two intersecting circles # if the radii and common chord length is given def distcenter(r1, r2, x): z = (((r1 * r1) - (x / 2 * x / 2))**(1/2)) +\ (((r2 * r2)- (x / 2 * x / 2))**(1/2)); print("distance between thecenters is ",end=""); print(int(z)); # Driver code r1 = 24; r2 = 37; x = 40; distcenter(r1, r2, x); # This code has been contributed by 29AjayKumar
C#
// C# program to find // the distance between centers // of two intersecting circles // if the radii and common chord length is given using System; class GFG { static double distcenter(int r1, int r2, int x) { double z = (Math.Sqrt((r1 * r1) - (x / 2 * x / 2))) + (Math.Sqrt((r2 * r2) - (x / 2 * x / 2))); Console.WriteLine("distance between the" + " centers is "+ (int)z ); return 0; } // Driver code static public void Main () { int r1 = 24, r2 = 37, x = 40; distcenter(r1, r2, x); } } // This code is contributed by jit_t
PHP
<?php // php program to find // the distance between centers // of two intersecting circles // if the radii and common chord length is given function distcenter($r1, $r2, $x) { $z = sqrt(($r1 * $r1) - ($x / 2 * $x / 2)) + sqrt(($r2 * $r2) - ($x / 2 * $x / 2)); echo("distance between the centers is " ); echo((int)$z); } // Driver code $r1 = 24; $r2 = 37; $x = 40; distcenter($r1, $r2, $x); // This code is contributed by aditya942003patil ?>
Javascript
<script> // javascript program to find // the distance between centers // of two intersecting circles // if the radii and common chord length is given function distcenter(r1, r2, x) { var z = Math.sqrt((r1 * r1) - (x / 2 * x / 2)) + Math.sqrt((r2 * r2) - (x / 2 * x / 2)); document.write("distance between the centers is " + z); } // Driver code var r1 = 24,r2 = 37,x = 40; distcenter(r1, r2, x); // This code is contributed by aditya942003patil </script>
Producción :
la distancia entre los centros es 44
Complejidad de tiempo: O (1), ya que no se usa ningún bucle en el programa
Complejidad espacial: O(1), ya que no se utiliza espacio adicional.
Publicación traducida automáticamente
Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA