Dada una elipse con la mitad de los ejes mayor y menor de longitud A y B , la tarea es encontrar el área del triángulo isósceles más grande que se puede inscribir en la elipse cuyo vértice coincide con un extremo del eje mayor.
Ejemplos:
Entrada: A = 1, B = 2
Salida: 2,598
Explicación:
Área del triángulo isósceles = ((3 * √3) * A * B) / 4.
Por lo tanto, área = 2,598.Entrada: A = 2, B = 3
Salida: 7.794
Planteamiento: La idea se basa en la siguiente fórmula matemática:
Prueba:
Considerando el triángulo APB,
Área de APB = AB * PQ = (1 / 2) * A * B * (2 sin∅ – sin2∅)Derivando :
d(area(APB))/d∅ = ab ( cos∅ – cos2∅)Igualando la derivada a cero:
d(area(APB))/d∅ = 0
cos∅ = – (1 / 2)
∅ = 2PI / 3Por lo tanto, área de APB = (3√3) * A * B / 4
A continuación se muestra la implementación del enfoque anterior:
C++
// C++ program for the above approach #include <bits/stdc++.h> using namespace std; // Function to calculate area // of the isosceles triangle void triangleArea(float a, float b) { // If a and b are negative if (a < 0 || b < 0) { cout << -1; return; } // Stores the area of the triangle float area = (3 * sqrt(3) * a * b) / (4); // Print the area cout << area; } // Driver code int main() { // Given value of a & b float a = 1, b = 2; // Function call to find the // area of the isosceles triangle triangleArea(a, b); return 0; }
Java
// Java program for the above approach import java.util.*; class GFG { // Function to calculate area // of the isosceles triangle static void triangleArea(float a, float b) { // If a and b are negative if (a < 0 || b < 0) { System.out.println(-1); return; } // Stores the area of the triangle float area = (3 * (float)Math.sqrt(3) * a * b) / (4); // Print the area System.out.println(area); } // Driver Code public static void main(String[] args) { // Given value of a & b float a = 1, b = 2; // Function call to find the // area of the isosceles triangle triangleArea(a, b); } } // This code is contributed by sanjoy_62.
Python3
# Python 3 program for the above approach from math import sqrt # Function to calculate area # of the isosceles triangle def triangleArea(a, b): # If a and b are negative if (a < 0 or b < 0): print(-1) return # Stores the area of the triangle area = (3 * sqrt(3) * a * b) / (4); # Print the area print("{:.5f}".format(area)) # Driver code if __name__ == '__main__': # Given value of a & b a = 1 b = 2 # Function call to find the # area of the isosceles triangle triangleArea(a, b) # This code is contributed by SURENDRA_GANGWAR.
C#
// C# program for the above approach using System; public class GFG { // Function to calculate area // of the isosceles triangle static void triangleArea(float a, float b) { // If a and b are negative if (a < 0 || b < 0) { Console.WriteLine(-1); return; } // Stores the area of the triangle float area = (3 * (float)Math.Sqrt(3) * a * b) / (4); // Print the area Console.WriteLine(area); } // Driver Code public static void Main(string[] args) { // Given value of a & b float a = 1, b = 2; // Function call to find the // area of the isosceles triangle triangleArea(a, b); } } // This code is contributed by AnkThon
Javascript
<script> // Javascript program for the above approach // Function to calculate area // of the isosceles triangle function triangleArea(a, b) { // If a and b are negative if (a < 0 || b < 0) { document.write(-1); return; } // Stores the area of the triangle var area = (3 * Math.sqrt(3) * a * b) / (4); // Print the area document.write(area.toFixed(5)); } // Driver Code // Given value of a & b var a = 1, b = 2; // Function call to find the // area of the isosceles triangle triangleArea(a, b); // This code is contributed by todaysgaurav </script>
2.59808
Tiempo Complejidad: O(1)
Espacio Auxiliar: O(1)
Publicación traducida automáticamente
Artículo escrito por thotasravya28 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA