Biggest Reuleaux Triangle inscribed within a square which is inscribed within a hexagon
Last Updated :
07 Aug, 2022
Given a regular hexagon of side length a which inscribes a square which in turn inscribes a reuleaux triangle. The task is to find the maximum possible area of this reuleaux triangle.
Examples:
Input: a = 5
Output: 28.3287
Input: a = 9
Output: 91.7848
Approach: As the side of the square inscribed within a hexagon is x = 1.268a. Please refer Largest Square that can be inscribed within a hexagon.
Also, in the reuleaux triangle, h = x = 1.268a.
So, Area of the reuleaux triangle, A = 0.70477*h^2 = 0.70477*(1.268a)^2.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float Area( float a)
{
if (a < 0)
return -1;
float h = 1.268 * a;
float A = 0.70477 * pow (h, 2);
return A;
}
int main()
{
float a = 5;
cout << Area(a) << endl;
return 0;
}
|
Java
import java.io.*;
class GFG
{
static float Area( float a)
{
if (a < 0 )
return - 1 ;
float h =( float ) 1.268 * a;
float A = ( float )( 0.70477 * Math.pow(h, 2 ));
return A;
}
public static void main (String[] args)
{
float a = 5 ;
System.out.println( Area(a));
}
}
|
Python3
import math
def Area(a):
if (a < 0 ):
return - 1
h = 1.268 * a
A = 0.70477 * math. pow (h, 2 )
return A
a = 5
print (Area(a),end = "\n" )
|
C#
using System;
class GFG
{
static float Area( float a)
{
if (a < 0)
return -1;
float h =( float ) 1.268 * a;
float A = ( float )(0.70477 * Math.Pow(h, 2));
return A;
}
public static void Main ()
{
float a = 5;
Console.WriteLine(Area(a));
}
}
|
PHP
<?php
function Area( $a )
{
if ( $a < 0)
return -1;
$h = 1.268 * $a ;
$A = 0.70477 * pow( $h , 2);
return $A ;
}
$a = 5;
echo round (Area( $a ), 4);
?>
|
Javascript
<script>
function Area(a)
{
if (a < 0)
return -1;
let h = 1.268 * a;
let A = 0.70477 * Math.pow(h, 2);
return A;
}
let a = 5;
document.write(Area(a) + "<br>" );
</script>
|
Time complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...