📜  内接于半径为 R 的圆的等边三角形的面积

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

给定一个表示圆半径的整数R ,任务是找到与该圆内接的等边三角形的面积。

例子:

方法:让上面显示的三角形是一个等边三角形,表示为PQR

  • 三角形的面积可以计算为:
Area of triangle = (1/2) * Base * Height
  • 在这种情况下,Base 可以是PQ、PR 或 QR ,三角形的高度可以是PM 。因此,
Area of Triangle = (1/2) * QR * PM
  • 现在在三角形 ORQ上应用正弦定律,
RQ         OR
------  = -------
sin 60    sin 30

=> RQ = OR * sin60 / sin30
=> Side of Triangle = OR * sqrt(3)

As it is clearly observed
PM = PO + OM = r + r * sin30 = (3/2) * r
  • 因此,所需等边三角形的底和高将是:
Base = r * sqrt(3) = r * 1.732
Height = (3/2) * r
  • 借助上面给出的公式计算三角形的面积。

下面是上述方法的实现:

C++
// C++ implementation to find
// the area of the equilateral triangle
// inscribed in a circle of radius R
#include 
using namespace std;
 
// Function to find the area of
// equilateral triangle inscribed
// in a circle of radius R
double area(int R) {
      
     // Base and Height of
    // equilateral triangle
    double base = 1.732 * R;
    double height = (1.5) * R;
      
            // Area using Base and Height
    double area = 0.5 * base * height;
    return area;
}
 
// Driver Code
int main()
{
    int R = 7;
    cout<<(area(R));
    return 0;
}
 
// This code is contributed by 29AjayKumar


Java
// Java implementation to find
// the area of the equilateral triangle
// inscribed in a circle of radius R
class GFG
{
    // Function to find the area of
    // equilateral triangle inscribed
    // in a circle of radius R
    static double area(int R) {
         
                // Base and Height of
        // equilateral triangle
        double base = 1.732 * R;
        double height = (1.5) * R;
         
                // Area using Base and Height
        double area = 0.5 * base * height;
        return area;
    }
 
    // Driver code
    public static void main(String[] args) {
        int R = 7;
        System.out.println(area(R));
 
    }
}
 
// This code is contributed by 29AjayKumar


Python3
# Python 3 implementation to find
# the area of the equilateral triangle
# inscribed in a circle of radius R
 
# Function to find the area of
# equilateral triangle inscribed
# in a circle of radius R
def area(R):
    # Base and Height of
    # equilateral triangle
    base = 1.732 * R
    height = ( 3 / 2 ) * R
     
    # Area using Base and Height
    area = (( 1 / 2 ) * base * height )
    return area
     
# Driver Code
if __name__=='__main__':
    R = 7
    print(area(R))


C#
// C# implementation to find
// the area of the equilateral triangle
// inscribed in a circle of radius R
using System;
 
class GFG
{
    // Function to find the area of
    // equilateral triangle inscribed
    // in a circle of radius R
    static double area(int R)
    {
         
        // Base and Height of
        // equilateral triangle
        double Base = 1.732 * R;
        double height = (1.5) * R;
         
        // Area using Base and Height
        double area = 0.5 * Base * height;
        return area;
    }
 
    // Driver code
    public static void Main(String[] args)
    {
        int R = 7;
        Console.WriteLine(area(R));
    }
}
 
// This code is contributed by 29AjayKumar


Javascript


输出:
63.651

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