📜  计算椭圆内切三角形的面积与辅助圆上对应点形成的三角形的面积比

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

给定两个整数AB,分别代表椭圆的长半轴和半短轴的长度,任务是计算椭圆内切三角形与其辅助圆上对应点形成的三角形的比值.

例子:

方法:

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

  • 设椭圆上的 3 个点为P(a cosX, b sinX), Q(a cosY, b sinY), R(a cosZ, b sinZ)。
  • 因此,辅助圆上的对应点为A(a cosX, a sinX), B(a cosY, a sinY), C(a cosZ, a sinZ)。
  • 现在,使用公式使用三角形的给定点计算三角形的面积。

请按照以下步骤解决问题:

  • 将椭圆的长半轴与短半轴的比率存储在一个变量中,例如结果。
  • 打印结果的值作为所需的答案。  

下面是上述方法的实现:

C++
// C++ program for the above approach
#include 
using namespace std;
 
// Function to calculate ratio of a
// triangle inscribed in an ellipse to
// the triangle on the auxiliary circle
void triangleArea(int a, int b)
{
    // Stores the ratio of the
    // semi-major to semi-minor axes
    double ratio = (double)b / a;
 
    // Print the ratio
    cout << ratio;
}
 
// Driver Code
int main()
{
    int a = 1, b = 2;
    triangleArea(a, b);
 
    return 0;
}


Java
// Java program for the above approach
class GFG{
  
// Function to calculate ratio of a
// triangle inscribed in an ellipse to
// the triangle on the auxiliary circle
static void triangleArea(int a, int b)
{
     
    // Stores the ratio of the
    // semi-major to semi-minor axes
    double ratio = (double)b / a;
 
    // Print the ratio
    System.out.println(ratio);
}
 
// Driver Code
public static void main(String args[])
{
    int a = 1, b = 2;
     
    triangleArea(a, b);
}
}
 
// This code is contributed by AnkThon


Python3
# Python3 program for the above approach
 
# Function to calculate ratio of a
# triangle inscribed in an ellipse to
# the triangle on the auxiliary circle
def triangleArea(a, b):
 
    # Stores the ratio of the
    # semi-major to semi-minor axes
    ratio = b / a
 
    # Print the ratio
    print(ratio)
 
# Driver Code
if __name__ == "__main__" :
 
    a = 1
    b = 2
     
    triangleArea(a, b)
 
# This code is contributed by AnkThon


C#
// C# program for the above approach
using System;
using System.Collections.Generic;
 
class GFG{
  
// Function to calculate ratio of a
// triangle inscribed in an ellipse to
// the triangle on the auxiliary circle
static void triangleArea(int a, int b)
{
     
    // Stores the ratio of the
    // semi-major to semi-minor axes
    double ratio = (double)b / a;
 
    // Print the ratio
    Console.WriteLine(ratio);
}
 
// Driver Code
public static void Main()
{
    int a = 1, b = 2;
     
    triangleArea(a, b);
}
}
 
// This code is contributed by bgangwar59


Javascript


输出:
2

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

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