Biggest Reuleaux Triangle within a Square which is inscribed within a Right angle Triangle
Given here is a right angle triangle with height l, base b & hypotenuse h, 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: l = 5, b = 12, h = 13
Output: 8.77914
Input: l = 3, b = 4, h = 5
Output: 2.07116
Approach: We know, the side of the square inscribed within a right angled triangle is, a = (l*b)/(l+b), please refer Area of a largest square fit in a right angle triangle.
Also, in the reuleaux triangle, x = a.
So, x = (l*b)/(l+b).
So, Area of the Reuleaux Triangle is, A = 0.70477*x^2 = 0.70477*((l*b)/(l+b))^2.
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float Area( float l, float b, float h)
{
if (l < 0 || b < 0 || h < 0)
return -1;
float x = (l * b) / (l + b);
float A = 0.70477 * pow (x, 2);
return A;
}
int main()
{
float l = 5, b = 12, h = 13;
cout << Area(l, b, h) << endl;
return 0;
}
|
Java
import java.util.*;
import java.text.DecimalFormat;
class GFG
{
static double Area( double l, double b, double h)
{
if (l < 0 || b < 0 || h < 0 )
return - 1 ;
double x = (l * b) / (l + b);
double A = 0.70477 * Math.pow(x, 2 );
return A;
}
public static void main(String args[])
{
double l = 5 , b = 12 , h = 13 ;
DecimalFormat df = new DecimalFormat( "#,###,##0.00000" );
System.out.println(df.format(Area(l, b, h)));
}
}
|
Python3
import math as mt
def Area(l, b, h):
if (l < 0 or b < 0 or h < 0 ):
return - 1
x = (l * b) / (l + b)
A = 0.70477 * pow (x, 2 )
return A
l, b, h = 5 , 12 , 13
print (Area(l, b, h))
|
C#
using System;
class GFG
{
static double Area( double l, double b, double h)
{
if (l < 0 || b < 0 || h < 0)
return -1;
double x = (l * b) / (l + b);
double A = 0.70477 * Math.Pow(x, 2);
return A;
}
public static void Main()
{
double l = 5, b = 12, h = 13;
Console.WriteLine((Area(l, b, h)));
}
}
|
PHP
<?php
function Area( $l , $b , $h )
{
if ( $l < 0 or $b < 0 or $h < 0)
return -1;
$x = ( $l * $b ) / ( $l + $b );
$A = 0.70477 * pow( $x , 2);
return $A ;
}
$l = 5; $b = 12; $h = 13;
echo Area( $l , $b , $h );
?>
|
Javascript
<script>
function Area(l,b,h)
{
if (l < 0 || b < 0 || h < 0)
return -1;
let x = (l * b) / (l + b);
let A = 0.70477 * Math.pow(x, 2);
return A;
}
let l = 5, b = 12, h = 13;
document.write( Area(l,b,h).toFixed(5));
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
07 Aug, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...