Given here is a semicircle of radius r 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 : x = 5
Output : 14.0954
Input : x = 8
Output : 36.0842

Approach:We know, the side of the square inscribed within a semicircle is, a = 2r/?5. (Please refer here)
Also, in the reuleaux triangle, x = a.
So, x = 2*r/?5
So, Area of Reuleaux Triangle:
A = 0.70477*x^2 = 0.70477*(r^2/5)
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float Area( float r)
{
if (r < 0)
return -1;
float x = (2 * r) / sqrt (5);
float A = 0.70477 * pow (x, 2);
return A;
}
int main()
{
float r = 5;
cout << Area(r) << endl;
return 0;
}
|
Java
import java.lang.Math;
class GFG
{
static float Area( float r)
{
if (r < 0 )
return - 1 ;
float x = ( 2 * r) /( float )(Math.sqrt( 5 ));
float A = 0 .70477f *( float )(Math.pow(x, 2 ));
return A;
}
public static void main(String[] args)
{
float r = 5 ;
System.out.println(Area(r));
}
}
|
Python3
import math as mt
def Area(r):
if (r < 0 ):
return - 1
x = ( 2 * r) / mt.sqrt( 5 )
A = 0.70477 * pow (x, 2 )
return A
r = 5
print (Area(r))
|
C#
using System;
class GFG
{
static double Area( double r)
{
if (r < 0)
return -1;
double x = (2 * r) / ( double )(Math.Sqrt(5));
double A = 0.70477 * ( double )(Math.Pow(x, 2));
return A;
}
public static void Main()
{
double r = 5;
Console.WriteLine(Area(r));
}
}
|
PHP
<?php
function Area( $r )
{
if ( $r < 0)
return -1;
$x = (2 * $r ) / sqrt(5);
$A = 0.70477 * pow( $x , 2);
return $A ;
}
$r = 5;
echo Area( $r );
?>
|
Javascript
<script>
function Area(r)
{
if (r < 0)
return -1;
var x = (2 * r) /(Math.sqrt(5));
var A = 0.70477 *(Math.pow(x, 2));
return A;
}
var r = 5;
document.write(Area(r).toFixed(4));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)