📌  相关文章
📜  可以内接在矩形内的最大椭圆,内接于半圆内的矩形

📅  最后修改于: 2021-04-22 00:25:33             🧑  作者: Mango

在此给出半径为r的半圆,该半圆内接一个矩形,然后再内接一个椭圆形。任务是找到这个最大椭圆的面积。
例子:

Input: r = 5
Output: 19.625

Input: r = 11
Output: 94.985

方法

  1. 设矩形的长度= l和矩形的宽度= b
  2. 设椭圆的长轴的长度为2x ,椭圆的短轴的长度为2y
  3. 众所周知,半圆内最大矩形的长度和宽度分别为r /√2√2r (请参阅此处)
  4. 另外,矩形内的椭圆面积= (π* l * b)/ 4 = (πr^ 2/4)

下面是上述方法的实现

C++
// C++ Program to find the biggest ellipse
// which can be inscribed within a rectangle
// which in turn is inscribed within a semicircle
 
#include 
using namespace std;
 
// Function to find the area
// of the biggest ellipse
float ellipsearea(float r)
{
 
    // the radius cannot be negative
    if (r < 0)
        return -1;
 
    // area of the ellipse
    float a = (3.14 * r * r) / 4;
 
    return a;
}
 
// Driver code
int main()
{
    float r = 5;
    cout << ellipsearea(r) << endl;
    return 0;
}


Java
// Java Program to find the biggest ellipse
// which can be inscribed within a rectangle
// which in turn is inscribed within a semicircle
class GFG
{
 
// Function to find the area
// of the biggest ellipse
static float ellipsearea(float r)
{
 
    // the radius cannot be negative
    if (r < 0)
        return -1;
 
    // area of the ellipse
    float a = (float)((3.14f * r * r) / 4);
 
    return a;
}
 
// Driver code
public static void main(String[] args)
{
    float r = 5;
    System.out.println(ellipsearea(r));
}
}
 
// This code is contributed by Code_Mech.


Python3
# Python3 Program to find the biggest ellipse
# which can be inscribed within a rectangle
# which in turn is inscribed within a semicircle
 
# Function to find the area of
# the biggest ellipse
def ellipsearea(r) :
 
    # the radius cannot be negative
    if (r < 0) :
        return -1;
 
    # area of the ellipse
    a = (3.14 * r * r) / 4;
 
    return a;
 
# Driver code
if __name__ == "__main__" :
 
    r = 5;
    print(ellipsearea(r));
 
# This code is contributed by Ryuga


C#
// C# Program to find the biggest ellipse
// which can be inscribed within a rectangle
// which in turn is inscribed within a semicircle
using System;
class GFG
{
 
// Function to find the area
// of the biggest ellipse
static float ellipsearea(float r)
{
 
    // the radius cannot be negative
    if (r < 0)
        return -1;
 
    // area of the ellipse
    float a = (float)((3.14 * r * r) / 4);
 
    return a;
}
 
// Driver code
public static void Main()
{
    float r = 5;
    Console.WriteLine(ellipsearea(r));
}
}
 
// This code is contributed by Akanksha Rai


PHP


Javascript


输出:
19.625