📜  内切圆的正方形内切六边形的面积

📅  最后修改于: 2021-05-31 22:36:00             🧑  作者: Mango

给定具有边A的正六边形,边A刻有半径为r的圆,而半径r则内接了边a的正方形。任务是找到该正方形的面积。
例子

Input :  A = 5
Output : 37.5

Input : A = 8
Output : 96

方法
我们知道六边形内切圆的半径为r =A√3/ 2 (请参阅此处)
另外,圆内圆的边长为a =√r=√3A/√2
因此,正方形的面积面积=(√3A/√2)^ 2

C++
// C++ Program to find the area of the square
// inscribed within the circle which in turn
// is inscribed in a hexagon
#include 
using namespace std;
 
// Function to find the area of the square
float area(float a)
{
 
    // side of hexagon cannot be negative
    if (a < 0)
        return -1;
 
    // area of the square
    float area = pow((a * sqrt(3)) / (sqrt(2)), 2);
    return area;
}
 
// Driver code
int main()
{
    float a = 5;
    cout << area(a) << endl;
    return 0;
}


Java
// Java Program to find the area of the square
// inscribed within the circle which in turn
// is inscribed in a hexagon
 
import java.io.*;
 
class GFG {
 
// Function to find the area of the square
static float area(float a)
{
 
    // side of hexagon cannot be negative
    if (a < 0)
        return -1;
 
    // area of the square
    float area = (float)Math.pow((a * Math.sqrt(3)) / (Math.sqrt(2)), 2);
    return area;
}
 
// Driver code
    public static void main (String[] args) {
        float a = 5;
    System.out.println( area(a));
    }
}
// This code is contributed by ajit


Python3
# Python 3 Program to find the area
# of the square inscribed within the
# circle which in turn is inscribed
# in a hexagon
from math import pow, sqrt
 
# Function to find the area
# of the square
def area(a):
     
    # side of hexagon cannot
    # be negative
    if (a < 0):
        return -1
 
    # area of the square
    area = pow((a * sqrt(3)) /
                   (sqrt(2)), 2)
    return area
 
# Driver code
if __name__ == '__main__':
    a = 5
    print("{0:.3}".format(area(a)))
 
# This code is contributed
# by SURENDRA_GANGWAR


C#
// C# Program to find the area of
// the square inscribed within the
// circle which in turn is inscribed
// in a hexagon
using System;
 
class GFG
{
 
// Function to find the area
// of the square
static float area(float a)
{
 
    // side of hexagon cannot be negative
    if (a < 0)
        return -1;
 
    // area of the square
    float area = (float)Math.Pow((a * Math.Sqrt(3)) /
                                 (Math.Sqrt(2)), 2);
    return area;
}
 
// Driver code
public static void Main ()
{
    float a = 5;
    Console.WriteLine( area(a));
}
}
 
// This code is contributed by inder_verma..


PHP


Javascript


输出:
37.5