Area of the biggest ellipse inscribed within a rectangle - GeeksforGeeks

18 Mar, 2021
Given here is a rectangle of length l & breadth b, the task is to find the area of the biggest ellipse that can be inscribed within it.Examples:  
Input: l = 5, b = 3
Output: 11.775

Input: 7, b = 4
Output: 21.98
 
 
Approach:  
Let, the length of the major axis of the ellipse = 2x and the length of the minor axis of the ellipse = 2yFrom the diagram, it is very clear that, 2x = l 2y = b  So, Area of the ellipse = (π * x * y) = (π * l * b) / 4
Let, the length of the major axis of the ellipse = 2x and the length of the minor axis of the ellipse = 2y
From the diagram, it is very clear that, 2x = l 2y = b  
So, Area of the ellipse = (π * x * y) = (π * l * b) / 4
Below is the implementation of the above approach: 
C++
Java
Python3
C#
PHP
Javascript
// C++ Program to find the biggest ellipse// which can be inscribed within the rectangle #include <bits/stdc++.h>using namespace std; // Function to find the area// of the ellipsefloat ellipse(float l, float b){     // The sides cannot be negative    if (l < 0 || b < 0)        return -1;     // Area of the ellipse    float x = (3.14 * l * b) / 4;     return x;} // Driver codeint main(){    float l = 5, b = 3;    cout << ellipse(l, b) << endl;     return 0;}
// Java Program to find the biggest rectangle// which can be inscribed within the ellipseimport java.util.*;import java.lang.*;import java.io.*; class GFG{     // Function to find the area// of the rectanglestatic float ellipse(float l, float b){         // a and b cannot be negative    if (l < 0 || b < 0)        return -1;    float x = (float)(3.14 * l * b) / 4;     return x;     }     // Driver codepublic static void main(String args[]){    float a = 5, b = 3;    System.out.println(ellipse(a, b));}} // This code is contributed// by Mohit Kumar
# Python3 Program to find the biggest ellipse# which can be inscribed within the rectangle # Function to find the area# of the ellipsedef ellipse(l, b):     # The sides cannot be negative    if l < 0 or b < 0:        return -1     # Area of the ellipse    x = (3.14 * l * b) / 4     return x # Driver codeif __name__ == "__main__":     l, b = 5, 3    print(ellipse(l, b)) # This code is contributed# by Rituraj Jain
// C# Program to find the biggest rectangle// which can be inscribed within the ellipseusing System; class GFG{     // Function to find the area// of the rectanglestatic float ellipse(float l, float b){         // a and b cannot be negative    if (l < 0 || b < 0)        return -1;    float x = (float)(3.14 * l * b) / 4;     return x;     }     // Driver codepublic static void Main(){    float a = 5, b = 3;    Console.WriteLine(ellipse(a, b));}} // This code is contributed// by Code_Mech.
<?php// PHP Program to find the biggest ellipse// which can be inscribed within the rectangle // Function to find the area// of the ellipsefunction ellipse($l, $b){     // The sides cannot be negative    if ($l < 0 || $b < 0)        return -1;     // Area of the ellipse    $x = (3.14 * $l * $b) / 4;     return $x;} // Driver code$l = 5; $b = 3;echo ellipse($l, $b) . "\n"; // This code is contributed// by Akanksha Rai?>
<script> // javascript Program to find the biggest rectangle// which can be inscribed within the ellipse   // Function to find the area// of the rectanglefunction ellipse(l , b){         // a and b cannot be negative    if (l < 0 || b < 0)        return -1;    var x = (3.14 * l * b) / 4;     return x;     }     // Driver code var a = 5, b = 3;document.write(ellipse(a, b));  // This code is contributed by Amit Katiyar </script>
11.775
 
rituraj_jain
mohit kumar 29
Akanksha_Rai
Code_Mech
amit143katiyar
area-volume-programs
school-programming
Geometric
Mathematical
Mathematical
Geometric
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Given n line segments, find if any two segments intersect
Program to check if three points are collinear
Closest Pair of Points | O(nlogn) Implementation
Check if a point lies inside a rectangle | Set-2
C++ Program to Illustrate Trigonometric functions
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Coin Change | DP-7