Area of a circle inscribed in a regular hexagon - GeeksforGeeks

16 Mar, 2021
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 degThen in right angled triangle OAM, 
tanx = tan30 = 1/√3 So, a/2r = 1/√3 Therefore, r = a√3/2 Area of circle, A =Πr2=Π3a^2/4
Below is the implementation of the approach:  
C++
Java
Python 3
C#
PHP
Javascript
// C++ Program to find the area of the circle// which can be inscribed within the hexagon#include <bits/stdc++.h>using namespace std; // Function to find the area// of the inscribed circlefloat circlearea(float a){     // the side cannot be negative    if (a < 0)        return -1;     // area of the circle    float A = (3.14 * 3 * pow(a, 2)) / 4;     return A;} // Driver codeint main(){    float a = 4;    cout << circlearea(a) << endl;     return 0;}
//Java program to find the//area of the circle//which can be inscribed within the hexagon import java.util.*; class solution{static double circlearea(double a){ // the side cannot be negative    if (a < 0)    return -1; // area of the circle    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 program to find the# area of the circle# which can be inscribed within the hexagon # Function to find the area# of the inscribed circledef circlearea(a) :     # the side cannot be negative    if a < 0 :        return -1     #  area of the circle    A = (3.14 * 3 * pow(a,2)) / 4     return A  # Driver code    if __name__ == "__main__" :     a = 4    print(circlearea(a))  # This code is contributed by ANKITRAI1
// C# program to find // the area of the circle// which can be inscribed// within the hexagonusing System; class GFG{static double circlearea(double a){     // the side cannot be negative    if (a < 0)    return -1;     // area of the circle    double A = (3.14 * 3 *                Math.Pow(a, 2)) / 4;     return A;} // Driver Codepublic static void Main(){    double a = 4;    Console.WriteLine(circlearea(a));}} // This code is contributed// by inder_verma
<?php// PHP Program to find the area of// the circle which can be inscribed// within the hexagon // Function to find the area// of the inscribed circlefunction circlearea($a){     // the side cannot be negative    if ($a < 0)        return -1;     // area of the circle    $A = (3.14 * 3 * pow($a, 2)) / 4;     return $A;} // Driver code$a = 4;echo circlearea($a) . "\n"; // This code is contributed// by Akanksha Rai(Abby_akku)
<script> // javascript program to find the//area of the circle//which can be inscribed within the hexagon function circlearea(a) {     // the side cannot be negative    if (a < 0)        return -1;     // area of the circle    var A = (3.14 * 3 * Math.pow(a, 2)) / 4;     return A;} var a = 4;document.write(circlearea(a)); // This code is contributed by 29AjayKumar </script>
37.68
 
ankthon
SURENDRA_GANGWAR
inderDuMCA
Akanksha_Rai
29AjayKumar
area-volume-programs
Technical Scripter 2018
Geometric
Mathematical
Technical Scripter
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Line Clipping | Set 1 (Cohen–Sutherland Algorithm)
Closest Pair of Points | O(nlogn) Implementation
Convex Hull | Set 2 (Graham Scan)
Given n line segments, find if any two segments intersect
Equation of circle when three points on the circle are given
Program for Fibonacci numbers
C++ Data Types
Write a program to print all permutations of a given string
Set in C++ Standard Template Library (STL)
Coin Change | DP-7