Dado un polígono de n lados con longitud de lado a . La tarea es encontrar el área del circuncírculo del polígono.
Ejemplos:
Input: n = 10, a = 3 Output: 1.99737
Input: n = 5, a = 6 Output: 3.02487
Enfoque : un n -ágono regular divide el círculo en n partes, por lo que el ángulo central del triángulo es un círculo completo dividido por n : 360 grados/n .
Aplicando la ley de los cosenos para las longitudes de los tres lados del triángulo, obtenemos
c2 = a2 + b2 - 2ab cos C or, a2 = r2 + r2 - 2rr cos (360/n) or, a2 = 2r2 - 2r2 cos (360/n) or, c2 = r2 (2 - 2 cos (360/n)) so, a=r√(2-2cos(360/n)) Therefore, r=a/√(2-2cos(360/n))
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ Program to find the radius // of the circumcircle of the given polygon #include <bits/stdc++.h> using namespace std; // Function to find the radius // of the circumcircle float findRadiusOfcircumcircle(float n, float a) { // these cannot be negative if (n < 0 || a < 0) return -1; // Radius of the circumcircle float radius = a / sqrt(2 - (2 * cos(360 / n))); // Return the radius return radius; } // Driver code int main() { float n = 5, a = 6; // Find the radius of the circumcircle cout << findRadiusOfcircumcircle(n, a) << endl; return 0; }
Java
// Java Program to find the radius // of the circumcircle of the given polygon import java.io.*; class GFG { // Function to find the radius // of the circumcircle static float findRadiusOfcircumcircle(float n, float a) { // these cannot be negative if (n < 0 || a < 0) return -1; // Radius of the circumcircle float radius = (float)(a / Math.sqrt(2 - (2 * Math.cos(360 / n)))); // Return the radius return radius; } // Driver code public static void main (String[] args) { float n = 5, a = 6; // Find the radius of the circumcircle System.out.println( findRadiusOfcircumcircle(n, a)) ; } } // This code is contributed // by anuj_67..
Python 3
# Python3 Program to find the # radius of the circumcircle # of the given polygon # from math import all methods from math import * # Function to find the radius # of the circumcircle def findRadiusOfcircumcircle(n, a) : # these cannot be negative if n < 0 or a < 0 : return -1 # Radius of the circumcircle radius = a / sqrt(2 - (2 * cos(360 / n))) # Return the radius return radius # Driver code if __name__ == "__main__" : n , a = 5, 6 # Find the radius of the circumcircle print(round(findRadiusOfcircumcircle(n, a), 5)) # This code is contributed # by ANKITRAI1
C#
// C# Program to find the radius // of the circumcircle of the given polygon using System; class GFG { // Function to find the radius // of the circumcircle static float findRadiusOfcircumcircle(float n, float a) { // these cannot be negative if (n < 0 || a < 0) return -1; // Radius of the circumcircle float radius = (float)(a / Math.Sqrt(2 - (2 * Math.Cos(360 / n)))); // Return the radius return radius; } // Driver code public static void Main () { float n = 5, a = 6; // Find the radius of the circumcircle Console.WriteLine(findRadiusOfcircumcircle(n, a)); } } // This code is contributed // by anuj_67
PHP
<?php // PHP Program to find the radius // of the circumcircle of the // given polygon // Function to find the radius // of the circumcircle function findRadiusOfcircumcircle($n, $a) { // these cannot be negative if ($n < 0 || $a < 0) return -1; // Radius of the circumcircle $radius = $a / sqrt(2 - (2 * cos(360 / $n))); // Return the radius return $radius; } // Driver code $n = 5; $a = 6; // Find the radius of the circumcircle echo findRadiusOfcircumcircle($n, $a); // This code is contributed by Anuj_67.. ?>
Javascript
<script> // javascript Program to find the radius // of the circumcircle of the given polygon // Function to find the radius // of the circumcircle function findRadiusOfcircumcircle(n , a) { // these cannot be negative if (n < 0 || a < 0) return -1; // Radius of the circumcircle var radius = (a / Math.sqrt(2 - (2 * Math.cos(360 / n)))); // Return the radius return radius; } // Driver code var n = 5, a = 6; // Find the radius of the circumcircle document.write( findRadiusOfcircumcircle(n, a).toFixed(5)) ; // This code is contributed by shikhasingrajput </script>
Producción:
3.02487
Tiempo Complejidad: 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