📜  六角形面积

📅  最后修改于: 2021-04-30 02:41:44             🧑  作者: Mango

六边形是6边的2维几何图形。任何六角形的内角总和为720°。正六边形具有6个旋转对称和6个反射对称。所有内角均为120度。

例子 :

Input: 4
Output: 41.5692

Input: 6
Output: 93.5307

公式如何运作? n边主要有6个等边三角形,等边三角形的面积为(sqrt(3)/ 4)* n * n。由于在六边形中,总共有6个边为n的等边三角形,所以六边形的(3 * sqrt(3)/ 2)* n * n

C++
// CPP program to find
// area of a Hexagon
#include 
#include 
using namespace std;
 
// function for calculating
// area of the hexagon.
double hexagonArea(double s)
{
    return ((3 * sqrt(3) *
            (s * s)) / 2);    
}
 
// Driver Code
int main()
{
    // Length of a side
    double s = 4;
    cout << "Area : "
         << hexagonArea(s);
    return 0;
}


Java
class GFG
{
    // Create a function for calculating
    // the area of the hexagon.
    public static double hexagonArea(double s)
    {
        return ((3 * Math.sqrt(3) *
                (s * s)) / 2);
    }
         
    // Driver Code
    public static void main(String[] args)
    {    
        // Length of a side
        double s = 4;     
        System.out.print("Area: " +
                          hexagonArea(s) );
    }
}


Python3
# Python3 program to find
# area of a Hexagon
import math
 
# Function for calculating
# area of the hexagon.
def hexagonArea(s):
     
    return ((3 * math.sqrt(3) *
            (s * s)) / 2);
     
# Driver code    
if __name__ == "__main__" :
 
    # length of a side.
    s = 4
 
    print("Area:","{0:.4f}" .
           format(hexagonArea(s)))
 
# This code is contributed by Naman_Garg


C#
// C# program to find
// area of a Hexagon
using System;
 
class GFG
{
     
    // Create a function for calculating
    // the area of the hexagon.
    public static double hexagonArea(double s)
    {
        return ((3 * Math.Sqrt(3) *
                (s * s)) / 2);
    }
         
    // Driver Code
    public static void Main()
    {
        // Length of a side
        double s = 4;
         
        Console.WriteLine("Area: " +
                           hexagonArea(s) );
    }
}
 
// This code is contributed by vt_m.


PHP


Javascript


输出 :

Area: 41.5692