Area of largest isosceles triangle that can be inscribed in an Ellipse whose vertex coincides with one extremity of the major axis
Last Updated :
11 Jun, 2021
Given an ellipse with half the major and minor axes length A & B, the task is to find the area of the largest isosceles triangle that can be inscribed in the ellipse whose vertex coincides with one extremity of the major axis.
Examples:
Input: A = 1, B = 2
Output: 2.598
Explanation:
Area of the isosceles triangle = ((3 * √3) * A * B) / 4.
Therefore, area = 2.598.
Input: A = 2, B = 3
Output: 7.794
Approach: The idea is based on the following mathematical formula:
Proof:
Considering triangle APB,
Area of APB = AB * PQ = (1 / 2) * A * B * (2 sin∅ – sin2∅)
Taking derivative:
d(area(APB))/d∅ = ab ( cos∅ – cos2∅)
Equating the derivative to zero:
d(area(APB))/d∅ = 0
cos∅ = – (1 / 2)
∅ = 2PI / 3
Therefore, area of APB = (3√3) * A * B / 4
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
void triangleArea( float a, float b)
{
if (a < 0 || b < 0) {
cout << -1;
return ;
}
float area = (3 * sqrt (3) * a * b) / (4);
cout << area;
}
int main()
{
float a = 1, b = 2;
triangleArea(a, b);
return 0;
}
|
Java
import java.util.*;
class GFG
{
static void triangleArea( float a, float b)
{
if (a < 0 || b < 0 ) {
System.out.println(- 1 );
return ;
}
float area = ( 3 * ( float )Math.sqrt( 3 ) * a * b) / ( 4 );
System.out.println(area);
}
public static void main(String[] args)
{
float a = 1 , b = 2 ;
triangleArea(a, b);
}
}
|
Python3
from math import sqrt
def triangleArea(a, b):
if (a < 0 or b < 0 ):
print ( - 1 )
return
area = ( 3 * sqrt( 3 ) * a * b) / ( 4 );
print ( "{:.5f}" . format (area))
if __name__ = = '__main__' :
a = 1
b = 2
triangleArea(a, b)
|
C#
using System;
public class GFG
{
static void triangleArea( float a, float b)
{
if (a < 0 || b < 0) {
Console.WriteLine(-1);
return ;
}
float area = (3 * ( float )Math.Sqrt(3) * a * b) / (4);
Console.WriteLine(area);
}
public static void Main( string [] args)
{
float a = 1, b = 2;
triangleArea(a, b);
}
}
|
Javascript
<script>
function triangleArea(a, b)
{
if (a < 0 || b < 0)
{
document.write(-1);
return ;
}
var area = (3 * Math.sqrt(3) * a * b) / (4);
document.write(area.toFixed(5));
}
var a = 1, b = 2;
triangleArea(a, b);
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Share your thoughts in the comments
Please Login to comment...