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 = 2Input: 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:
- Store the ratio of the semi-major axis to semi-minor axis of the ellipse in a variable, say result.
- Print the value of result as the required answer.
Below is the implementation of the above approach:
C++
// C++ program for the above approach #include <bits/stdc++.h> using namespace std; // Function to calculate ratio of a // triangle inscribed in an ellipse to // the triangle on the auxiliary circle void triangleArea( int a, int b) { // Stores the ratio of the // semi-major to semi-minor axes double ratio = ( double )b / a; // Print the ratio cout << ratio; } // Driver Code int main() { int a = 1, b = 2; triangleArea(a, b); return 0; } |
Java
// Java program for the above approach class GFG{ // Function to calculate ratio of a // triangle inscribed in an ellipse to // the triangle on the auxiliary circle static void triangleArea( int a, int b) { // Stores the ratio of the // semi-major to semi-minor axes double ratio = ( double )b / a; // Print the ratio System.out.println(ratio); } // Driver Code public static void main(String args[]) { int a = 1 , b = 2 ; triangleArea(a, b); } } // This code is contributed by AnkThon |
Python3
# Python3 program for the above approach # Function to calculate ratio of a # triangle inscribed in an ellipse to # the triangle on the auxiliary circle def triangleArea(a, b): # Stores the ratio of the # semi-major to semi-minor axes ratio = b / a # Print the ratio print (ratio) # Driver Code if __name__ = = "__main__" : a = 1 b = 2 triangleArea(a, b) # This code is contributed by AnkThon |
C#
// C# program for the above approach using System; using System.Collections.Generic; class GFG{ // Function to calculate ratio of a // triangle inscribed in an ellipse to // the triangle on the auxiliary circle static void triangleArea( int a, int b) { // Stores the ratio of the // semi-major to semi-minor axes double ratio = ( double )b / a; // Print the ratio Console.WriteLine(ratio); } // Driver Code public static void Main() { int a = 1, b = 2; triangleArea(a, b); } } // This code is contributed by bgangwar59 |
Javascript
<script> // JavaScript program for the above approach // Function to calculate ratio of a // triangle inscribed in an ellipse to // the triangle on the auxiliary circle function triangleArea(a, b){ // Stores the ratio of the // semi-major to semi-minor axes ratio = b / a // Print the ratio document.write(ratio) } // Driver Code var a = 1 var b = 2 triangleArea(a, b) // This code is contributed by AnkThon </script> |
Output:
2
Time Complexity: O(1)
Auxiliary Space: O(1)
Please Login to comment...