Biggest Reuleaux Triangle inscribed within a square which is inscribed within an ellipse
Given an ellipse with major axis length and minor axis 2a & 2b respectively 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, b = 4
Output: 0.0722389
Input: a = 7, b = 11
Output: 0.0202076
Approach: As, the side of the square inscribed within an ellipse is, x = ?(a^2 + b^2)/ab. Please refer Area of the Largest square that can be inscribed in an ellipse.
Also, in the reuleaux triangle, h = x = ?(a^2 + b^2)/ab.
So, Area of the reuleaux triangle, A = 0.70477*h^2 = 0.70477*((a^2 + b^2)/a^2b^2).
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float Area( float a, float b)
{
if (a < 0 && b < 0)
return -1;
float h = sqrt ((( pow (a, 2) + pow (b, 2))
/ ( pow (a, 2) * pow (b, 2))));
float A = 0.70477 * pow (h, 2);
return A;
}
int main()
{
float a = 5, b = 4;
cout << Area(a, b) << endl;
return 0;
}
|
Java
import java.io.*;
class GFG
{
static float Area( float a, float b)
{
if (a < 0 && b < 0 )
return - 1 ;
float h = ( float )Math.sqrt(((Math.pow(a, 2 ) + Math.pow(b, 2 ))
/ (Math.pow(a, 2 ) * Math.pow(b, 2 ))));
float A = ( float )( 0.70477 * Math.pow(h, 2 ));
return A;
}
public static void main (String[] args)
{
float a = 5 , b = 4 ;
System.out.println(Area(a, b));
}
}
|
Python3
import math;
def Area(a, b):
if (a < 0 and b < 0 ):
return - 1 ;
h = math.sqrt((( pow (a, 2 ) + pow (b, 2 )) /
( pow (a, 2 ) * pow (b, 2 ))));
A = 0.70477 * pow (h, 2 );
return A;
a = 5 ;
b = 4 ;
print ( round (Area(a, b), 7 ));
|
C#
using System;
class GFG
{
static double Area( double a, double b)
{
if (a < 0 && b < 0)
return -1;
double h = ( double )Math.Sqrt(((Math.Pow(a, 2) +
Math.Pow(b, 2)) /
(Math.Pow(a, 2) *
Math.Pow(b, 2))));
double A = ( double )(0.70477 * Math.Pow(h, 2));
return A;
}
static void Main()
{
double a = 5, b = 4;
Console.WriteLine(Math.Round(Area(a, b),7));
}
}
|
PHP
<?php
function Area( $a , $b )
{
if ( $a < 0 && $b < 0)
return -1;
$h = sqrt(((pow( $a , 2) + pow( $b , 2)) /
(pow( $a , 2) * pow( $b , 2))));
$A = 0.70477 * pow( $h , 2);
return $A ;
}
$a = 5;
$b = 4;
echo round (Area( $a , $b ), 7);
?>
|
Javascript
<script>
function Area(a, b)
{
if (a < 0 && b < 0)
return -1;
let h = Math.sqrt(((Math.pow(a, 2) + Math.pow(b, 2))
/ (Math.pow(a, 2) * Math.pow(b, 2))));
let A = 0.70477 * Math.pow(h, 2);
return A;
}
let a = 5, b = 4;
document.write(Area(a, b) + "<br>" );
</script>
|
Time Complexity: O(logn) as it is using inbuilt sqrt function
Auxiliary Space: O(1)
Last Updated :
27 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...