📜  计算等边三角形圆的面积和周长的程序

📅  最后修改于: 2021-05-04 07:35:25             🧑  作者: Mango

给定等边三角形的边长,任务是找到给定等边三角形的圆的面积和周长。

例子:

Input: side = 6 
Output: Area = 9.4. Perimeter = 10.88

Input: side = 9
Output: Area = 21.21, Perimeter = 16.32

圆的属性为:

  • 圆弧的中心与三角形的中心相同,即等边三角形的中值相交的点。
  • 等边三角形的内接圆是通过等边三角形边缘的中点制成的。
  • 等边三角形的圆的半径可以使用以下公式计算:

     a / (\sqrt3 * 2)

    在哪里 a 是等边三角形边的长度。

  • 下图显示了带有圆形的等边三角形:

  • 方法:

    圆的面积= \pi*r^2和圆的周长=  2 * \pi * r ,其中r是给定圆的半径。

    同样是等边三角形的Incirce半径=(等边三角形的边)/ 3。
    所以,

    1. 用于使用“半径”计算“圆”面积的公式为:

       \pi r^2  =>  ( \pi * a^2 ) / (3 * 2 )

    2. 用于使用“半径”计算“圆”周长的公式为:

       2 * \pi * r  =>  2 * \pi * (a/\sqrt3*2)

      C
      // C program to find the area of Inscribed circle 
      // of equilateral triangle
      #include 
      #include 
      #define PI 3.14159265
        
      // function to find area of inscribed circle
      float area_inscribed(float a)
      {
          return (a * a * (PI / 12));
      }
        
      // function to find Perimeter of inscribed circle
      float perm_inscribed(float a)
      {
          return (PI * (a / sqrt(3)));
      }
        
      // Driver code
      int main()
      {
          float a = 6;
          printf("Area of inscribed circle is :%f\n",
                 area_inscribed(a));
        
          printf("Perimeter of inscribed circle is :%f",
                 perm_inscribed(a));
        
          return 0;
      }


      Java
      // Java code to find the area of inscribed
      // circle of equilateral triangle
      import java.lang.*;
        
      class GFG {
        
          static double PI = 3.14159265;
        
          // function to find the area of
          // inscribed circle
          public static double area_inscribed(double a)
          {
              return (a * a * (PI / 12));
          }
        
          // function to find the perimeter of
          // inscribed circle
          public static double perm_inscribed(double a)
          {
              return (PI * (a / Math.sqrt(3)));
          }
        
          // Driver code
          public static void main(String[] args)
          {
              double a = 6.0;
              System.out.println("Area of inscribed circle is :"
                                 + area_inscribed(a));
        
              System.out.println("\nPerimeter of inscribed circle is :"
                                 + perm_inscribed(a));
          }
      }


      Python3
      # Python3 code to find the area of inscribed 
      # circle of equilateral triangle
      import math
      PI = 3.14159265
            
      # Function to find the area of 
      # inscribed circle
      def area_inscribed(a):
          return (a * a * (PI / 12))
        
      # Function to find the perimeter of 
      # inscribed circle
      def perm_inscribed(a):
          return ( PI * (a / math.sqrt(3) ) )    
        
        
      # Driver code
      a = 6.0
      print("Area of inscribed circle is :% f"
                              % area_inscribed(a))
      print("\nPerimeter of inscribed circle is :% f"
                              % perm_inscribed(a))


      C#
      // C# code to find the area of
      // inscribed circle
      // of equilateral triangle
      using System;
        
      class GFG {
          static double PI = 3.14159265;
        
          // function to find the area of
          // inscribed circle
          public static double area_inscribed(double a)
          {
              return (a * a * (PI / 12));
          }
        
          // function to find the perimeter of
          // inscribed circle
          public static double perm_inscribed(double a)
          {
              return (PI * (a / Math.Sqrt(3)));
          }
        
          // Driver code
          public static void Main()
          {
              double a = 6.0;
              Console.Write("Area of inscribed circle is :"
                            + area_inscribed(a));
        
              Console.Write("\nPerimeter of inscribed circle is :"
                            + perm_inscribed(a));
          }
      }


      PHP


      输出:
      Area of inscribed circle is :9.424778
      Perimeter of inscribed circle is :10.882796