Calculate ratio of area of a triangle inscribed in an Ellipse and the triangle formed by corresponding points on auxiliary circle
Given two integers A and B representing the lengths of semi-major and semi-minor axes of an ellipse, the task is to calculate the ratio of any triangle inscribed in the ellipse and that of the triangle formed by the corresponding points on its auxiliary circle.
Examples:
Input: A = 1, B = 2
Output: 2
Explanation: Ratio = B / A = 2 / 1 = 2
Input: A = 2, B = 3
Output: 1.5
Approach:
The idea is based on the following mathematical formula:
- Let the 3 points on the ellipse be P(a cosX, b sinX), Q(a cosY, b sinY), R(a cosZ, b sinZ).
- Therefore, the corresponding points on the auxiliary circles are A(a cosX, a sinX), B(a cosY, a sinY), C(a cosZ, a sinZ).
- Now, using the formula to calculate the area of triangle using the given points of the triangle.
Area(PQR) / Area(ABC) = b / a
Follow the steps below to solve the problem:
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
void triangleArea( int a, int b)
{
double ratio = ( double )b / a;
cout << ratio;
}
int main()
{
int a = 1, b = 2;
triangleArea(a, b);
return 0;
}
|
Java
class GFG{
static void triangleArea( int a, int b)
{
double ratio = ( double )b / a;
System.out.println(ratio);
}
public static void main(String args[])
{
int a = 1 , b = 2 ;
triangleArea(a, b);
}
}
|
Python3
def triangleArea(a, b):
ratio = b / a
print (ratio)
if __name__ = = "__main__" :
a = 1
b = 2
triangleArea(a, b)
|
C#
using System;
using System.Collections.Generic;
class GFG{
static void triangleArea( int a, int b)
{
double ratio = ( double )b / a;
Console.WriteLine(ratio);
}
public static void Main()
{
int a = 1, b = 2;
triangleArea(a, b);
}
}
|
Javascript
<script>
function triangleArea(a, b){
ratio = b / a
document.write(ratio)
}
var a = 1
var b = 2
triangleArea(a, b)
</script>
|
Time Complexity: O(1)
Auxiliary Space: O(1)
Last Updated :
16 Apr, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...