Area of a circle inscribed in a regular hexagon
Last Updated :
20 Aug, 2022
Given a regular Hexagon with side length a, the task is to find the area of the circle inscribed in it, given that, the circle is tangent to each of the six sides.
Examples:
Input: a = 4
Output: 37.68
Input: a = 10
Output: 235.5
Approach:
From the figure, it is clear that, we can divide the regular hexagon into 6 identical equilateral triangles.
We take one triangle OAB, with O as the centre of the hexagon or circle, & AB as one side of the hexagon.
Let M be mid-point of AB, OM would be the perpendicular bisector of AB, angle AOM = 30 deg
Then in right angled triangle OAM,
tanx = tan30 = 1/?3
So, a/2r = 1/?3
Therefore, r = a?3/2
Area of circle, A =?r²=?3a^2/4
Below is the implementation of the approach:
C++
#include <bits/stdc++.h>
using namespace std;
float circlearea( float a)
{
if (a < 0)
return -1;
float A = (3.14 * 3 * pow (a, 2)) / 4;
return A;
}
int main()
{
float a = 4;
cout << circlearea(a) << endl;
return 0;
}
|
Java
import java.util.*;
class solution
{
static double circlearea( double a)
{
if (a < 0 )
return - 1 ;
double A = ( 3.14 * 3 * Math.pow(a, 2 ) ) / 4 ;
return A;
}
public static void main(String arr[])
{
double a = 4 ;
System.out.println(circlearea(a));
}
}
|
Python 3
def circlearea(a) :
if a < 0 :
return - 1
A = ( 3.14 * 3 * pow (a, 2 )) / 4
return A
if __name__ = = "__main__" :
a = 4
print (circlearea(a))
|
C#
using System;
class GFG
{
static double circlearea( double a)
{
if (a < 0)
return -1;
double A = (3.14 * 3 *
Math.Pow(a, 2)) / 4;
return A;
}
public static void Main()
{
double a = 4;
Console.WriteLine(circlearea(a));
}
}
|
PHP
<?php
function circlearea( $a )
{
if ( $a < 0)
return -1;
$A = (3.14 * 3 * pow( $a , 2)) / 4;
return $A ;
}
$a = 4;
echo circlearea( $a ) . "\n" ;
|
Javascript
<script>
function circlearea(a) {
if (a < 0)
return -1;
var A = (3.14 * 3 * Math.pow(a, 2)) / 4;
return A;
}
var a = 4;
document.write(circlearea(a));
</script>
|
Time complexity: O(1)
Auxiliary Space: O(1)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...