📌  相关文章
📜  可以内接在立方体内的球体中可以内接的最大右圆锥

📅  最后修改于: 2021-04-24 20:23:25             🧑  作者: Mango

给定一个边长a的立方体,它刻有一个球体,而球体又刻有一个右圆锥。任务是找到此圆锥体的最大可能体积。
例子:

Input:  a = 5
Output: 58.1481

Input: a = 8
Output: 238.175

方法
令,右圆锥的高度= h
圆锥半径= r
球面半径= R
我们知道立方体内部球体的半径r = a / 2 。请参阅(可以在立方体内刻出的最大球体)。
同样,球体内的圆锥高度h = 4r / 3
球体内圆锥的半径, r =2√2r/ 3 。请参阅(可以在球体内刻入的最大右圆锥形)。
因此,球体内部的圆锥体的高度又被切入一个立方体, h = 2a / 3
球体内的圆锥半径(又接在一个立方体内), r =√2a/ 3
下面是上述方法的实现:

C++
// C++ Program to find the biggest right circular cone
// that can be inscribed within a right circular cone
// which in turn is inscribed within a cube
 
#include 
using namespace std;
 
// Function to find the biggest right circular cone
float cone(float a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // radius of right circular cone
    float r = (a * sqrt(2)) / 3;
 
    // height of right circular cone
    float h = (2 * a) / 3;
 
    // volume of right circular cone
    float V = 3.14 * pow(r, 2) * h;
 
    return V;
}
 
// Driver code
int main()
{
    float a = 5;
    cout << cone(a) << endl;
 
    return 0;
}


Java
// Java Program to find the biggest right circular cone
// that can be inscribed within a right circular cone
// which in turn is inscribed within a cube
import java.io.*;
 
class GFG
{
     
// Function to find the biggest right circular cone
static float cone(float a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // radius of right circular cone
    float r = (float) (a * Math.sqrt(2)) / 3;
 
    // height of right circular cone
    float h = (2 * a) / 3;
 
    // volume of right circular cone
    float V = (float)(3.14 *Math. pow(r, 2) * h);
 
    return V;
}
 
// Driver code
public static void main (String[] args)
{
    float a = 5;
    System.out.println( cone(a));
}
}
 
// This code is contributed by anuj_67..


Python3
# Python3 Program to find the biggest right
# circular cone that can be inscribed within
# a right circular cone which in turn is
# inscribed within a cube
import math
 
# Function to find the biggest
# right circular cone
def cone(a):
 
    # side cannot be negative
    if (a < 0):
        return -1;
 
    # radius of right circular cone
    r = (a * math.sqrt(2)) / 3;
 
    # height of right circular cone
    h = (2 * a) / 3;
 
    # volume of right circular cone
    V = 3.14 * math.pow(r, 2) * h;
 
    return V;
 
# Driver code
a = 5;
print(cone(a));
 
# This code is contributed by
# Shivi_Aggarwal


C#
// C# Program to find the biggest
// right circular cone that can be
// inscribed within a right circular cone
// which in turn is inscribed within a cube
using System;
 
class GFG
{
     
// Function to find the biggest
// right circular cone
static double cone(double a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // radius of right circular cone
    double r = (double) (a * Math.Sqrt(2)) / 3;
 
    // height of right circular cone
    double h = (2 * a) / 3;
 
    // volume of right circular cone
    double V = (double)(3.14 * Math.Pow(r, 2) * h);
 
    return Math.Round(V,4);
}
 
// Driver code
static void Main ()
{
    double a = 5;
    Console.WriteLine(cone(a));
}
}
 
// This code is contributed by chandan_jnu


PHP


Javascript


输出:
58.1481