📜  计算椭球体积的程序

📅  最后修改于: 2021-10-23 08:43:01             🧑  作者: Mango

椭圆体,其所有平面横截面都是椭圆或圆的封闭曲面。椭圆体关于在中心相交的三个相互垂直的轴对称。它是一个三维封闭的几何形状,其所有平面截面都是椭圆或圆形。
椭球体具有三个独立的轴,通常由三个半轴的长度 a、b、c 指定。如果一个椭球是通过一个椭圆绕它的一个轴旋转而形成的,那么这个椭球的两个轴是相同的,它被称为旋转椭球或椭球。如果它的三个轴的长度都相同,则它是一个球体。

Standard equation of Ellipsoid :
x2 / a2 + y2 / b2 + z2 / c2 = 1
   
where a, b, c are positive real numbers.
Volume of Ellipsoid :  (4/3) * pi * r1 * r2 * r3 

下面是计算椭球体积的代码:

C++
// CPP program to find the
// volume of Ellipsoid.
#include 
using namespace std;
 
// Function to find the volume
float volumeOfEllipsoid(float r1,
                        float r2,
                        float r3)
{
    float pi = 3.14;
    return 1.33 * pi * r1 *
                  r2 * r3;
}
 
// Driver Code
int main()
{
    float r1 = 2.3, r2 = 3.4, r3 = 5.7;
    cout << "volume of ellipsoid is : "
         << volumeOfEllipsoid(r1, r2, r3);
    return 0;
}


Java
// Java program to find the
// volume of Ellipsoid.
import java.util.*;
import java.lang.*;
 
class GfG
{
     
    // Function to find the volume
    public static float volumeOfEllipsoid(float r1,
                                          float r2,
                                          float r3)
    {
        float pi = (float)3.14;
        return (float) 1.33 * pi * r1 * r2 * r3;
    }
 
    // Driver Code
    public static void main(String args[])
    {
        float r1 = (float) 2.3,
              r2 = (float) 3.4,
              r3 = (float) 5.7;
        System.out.println("volume of ellipsoid is : "
                    + volumeOfEllipsoid(r1, r2, r3));
    }
}
 
// This code is contributed by Sagar Shukla


Python
''' Python3 program to Volume of ellipsoid'''
import math
 
# Function To calculate Volume
def volumeOfEllipsoid(r1, r2, r3):
    return 1.33 * math.pi * r1 * r2 * r3
 
 
# Driver Code
r1 = float(2.3)
r2 = float(3.4)
r3 = float(5.7)
print( "Volume of ellipsoid is : ",
        volumeOfEllipsoid(r1, r2, r3) )


C#
// C# program to find the
// volume of Ellipsoid.
using System;
 
class GfG
{
     
    // Function to find the volume
    public static float volumeOfEllipsoid(float r1,
                                            float r2,
                                            float r3)
    {
        float pi = (float)3.14;
        return (float) 1.33 * pi * r1 * r2 * r3;
    }
 
    // Driver Code
    public static void Main()
    {
        float r1 = (float)2.3,
            r2 =(float) 3.4,
            r3 = (float)5.7;
        Console.WriteLine("volume of ellipsoid is : " +
                        volumeOfEllipsoid(r1, r2, r3));
    }
}
 
// This code is contributed by vt_m


PHP


Javascript


输出 :

Volume of ellipsoid is : 186.15