📜  刻在半径为R的圆中的等边三角形的面积

📅  最后修改于: 2021-04-24 20:34:22             🧑  作者: Mango

给定表示圆半径的整数R ,任务是找到刻在该圆上的等边三角形的面积。

例子:

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

  • 三角形的面积可以计算为:
Area of triangle = (1/2) * Base * Height
  • 在这种情况下,“底数”可以是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