📜  可以刻在椭圆的顶点上的最大等腰三角形的面积,该椭圆的顶点与长轴的一个末端重合

📅  最后修改于: 2021-04-17 15:25:16             🧑  作者: Mango

给定长轴和短轴长度分别为AB一半的椭圆,任务是找到最大等腰三角形的面积,该面积可以刻在椭圆上,该椭圆的顶点与长轴的一个端点重合。

例子:

方法:该想法基于以下数学公式:

证明:

下面是上述方法的实现:

C++
// C++ program for the above approach
 
#include 
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 traingle
    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 traingle
    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 traingle
    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 traingle
    triangleArea(a, b);
  }
}
 
// This code is contributed by AnkThon


Javascript


输出:
2.59808

时间复杂度: O(1)
辅助空间: O(1)