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

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

给定两个整数AB表示椭圆的半长轴和半短轴的长度,任务是计算椭圆中所刻的任何三角形与由其辅助圆上的相应点形成的三角形的比率。

例子:

方法:

这个想法基于以下数学公式:

  • 令椭圆上的3个点为P(a cosX,b sinX),Q(a cosY,b sinY),R(a cosZ,b sinZ)。
  • 因此,辅助圆上的对应点是A(a cosX,sinX),B(a cosY,sinY),C(a cosZ,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)