📌  相关文章
📜  椭圆中可以内接的最大三角形

📅  最后修改于: 2021-10-23 08:33:04             🧑  作者: Mango

给定一个长轴长度为2a2b的椭圆,任务是找到可以内接的最大三角形的面积。
例子:

Input: a = 4, b = 2
Output: 10.3923

Input: a = 5, b = 3
Output: 10.8253

方法:所以我们知道椭圆只是一个圆的缩放阴影。让我们找到缩放因子。

这只是一个半径a 的垂直按比例缩小的圆(认为光线以一定角度从顶部落下),垂直系数是a/b 。椭圆中最大的三角形是圆中最大三角形的放大版本。使用一点几何学并考虑对称性,我们可以理解最大的三角形是等边三角形。它的边是√3a ,面积是(3√3)a^2/4
将其转换为椭圆项——我们将水平尺寸按因子a/b放大,椭圆中最大三角形的面积是,

下面是上述方法的实现:

C++
// C++ Program to find the biggest triangle
// which can be inscribed within the ellipse
#include 
using namespace std;
 
// Function to find the area
// of the triangle
float trianglearea(float a, float b)
{
 
    // a and b cannot be negative
    if (a < 0 || b < 0)
        return -1;
 
    // area of the triangle
    float area = (3 * sqrt(3) * pow(a, 2)) / (4 * b);
 
    return area;
}
 
// Driver code
int main()
{
    float a = 4, b = 2;
    cout << trianglearea(a, b) << endl;
 
    return 0;
}


Java
//Java Program to find the biggest triangle
//which can be inscribed within the ellipse
 
public class GFG {
 
    //Function to find the area
    //of the triangle
    static float trianglearea(float a, float b)
    {
 
     // a and b cannot be negative
     if (a < 0 || b < 0)
         return -1;
 
     // area of the triangle
     float area = (float)(3 * Math.sqrt(3) * Math.pow(a, 2)) / (4 * b);
 
     return area;
    }
 
    //Driver code
    public static void main(String[] args) {
     
        float a = 4, b = 2;
         System.out.println(trianglearea(a, b));
    }
}


Python3
# Python 3 Program to find the biggest triangle
# which can be inscribed within the ellipse
 
from math import *
 
# Function to find the area
# of the triangle
def trianglearea(a, b) :
 
    # a and b cannot be negative
    if a < 0 or b < 0 :
        return -1
 
    # area of the triangle
    area = (3 * sqrt(3) * pow(a, 2)) / (4 * b)
 
    return area
 
 
# Driver Code
if __name__ == "__main__" :
 
    a, b = 4, 2
    print(round(trianglearea(a, b),4))
 
 
# This code is contributed by ANKITRAI1


C#
// C# Program to find the biggest
// triangle which can be inscribed
// within the ellipse
using System;
 
class GFG
{
 
// Function to find the area
// of the triangle
static float trianglearea(float a, float b)
{
 
// a and b cannot be negative
if (a < 0 || b < 0)
    return -1;
 
// area of the triangle
float area = (float)(3 * Math.Sqrt(3) *
                         Math.Pow(a, 2)) / (4 * b);
 
return area;
}
 
// Driver code
public static void Main()
{
    float a = 4, b = 2;
    Console.WriteLine(trianglearea(a, b));
}
}
 
// This code is contributed
// by Akanksha Rai(Abby_akku)


PHP


Javascript


输出:
10.3923

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程