📌  相关文章
📜  可以内接在球体内的最大直圆锥

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

给定的半径球体r  .任务是找到可以内接的最大直圆锥的底半径和高。
例子

Input : R = 10
Output : r = 9.42809, h = 13.3333

Input : R = 25
Output : r = 23.5702, h = 33.3333

方法
让圆锥的半径 = r
锥体的高度 = h
从图中可以清楚地看出:
x = √(R^2 – r^2) 和 h=x+R
现在使用我们得到的这些值,

下面是上述方法的实现:

C++
*** QuickLaTeX cannot compile formula:
 

*** Error message:
Error: Nothing to show, formula is empty


Java
// C++ Program to find the biggest cone
// that can be inscribed within a sphere
#include 
using namespace std;
 
// Function to find the radius of the cone
float coner(float R)
{
 
    // radius cannot be negative
    if (R < 0)
        return -1;
 
    // radius of the cone
    float r = (2 * sqrt(2) * R) / 3;
    return r;
}
 
// Function to find the height of the cone
float coneh(float R)
{
 
    // side cannot be negative
    if (R < 0)
        return -1;
 
    // height of the cone
    float h = (4 * R) / 3;
    return h;
}
 
// Driver code
int main()
{
    float R = 10;
 
    cout << "r = " << coner(R) << ", "
         << "h = " << coneh(R) << endl;
 
    return 0;
}


Python3
// Java Program to find the biggest cone
// that can be inscribed within a sphere
import java.util.*;
import java.lang.*;
 
class GFG
{
// Function to find the radius
// of the cone
static float coner(float R)
{
    // radius cannot be negative
    if (R < 0)
        return -1;
 
    // radius of the cone
    float r = (float)(2 *
            Math.sqrt(2) * R) / 3;
    return r;
}
 
// Function to find the
// height of the cone
static float coneh(float R)
{
 
    // side cannot be negative
    if (R < 0)
        return -1;
 
    // height of the cone
    float h = (4 * R) / 3;
    return h;
}
 
// Driver code
public static void main(String args[])
{
    float R = 10;
 
    System.out.println("r = " + coner(R) +
                       ", " + "h = " + coneh(R));
}
}
 
// This code is contributed
// by Akanksha Rai


C#
# Python 3 Program to find the biggest cone
# that can be inscribed within a sphere
import math
 
# Function to find the radius
# of the cone
def coner(R):
     
    # radius cannot be negative
    if (R < 0):
        return -1;
     
    # radius of the cone
    r = (2 * math.sqrt(2) * R) / 3
    return float(r)
 
# Function to find the height
# of the cone
def coneh(R):
     
    # side cannot be negative
    if (R < 0):
        return -1;
 
    # height of the cone
    h = (4 * R) / 3
    return float(h)
 
# Driver code
R = 10
print("r = " , coner(R) ,
      ", ", "h = " , coneh(R))
 
# This code is contributed
# by 29AjayKumar


PHP
// C# Program to find the biggest cone
// that can be inscribed within a sphere
using System;
 
class GFG
{
// Function to find the radius
// of the cone
static float coner(float R)
{
    // radius cannot be negative
    if (R < 0)
        return -1;
 
    // radius of the cone
    float r = (float)(2 *
               Math.Sqrt(2) * R) / 3;
    return r;
}
 
// Function to find the
// height of the cone
static float coneh(float R)
{
 
    // side cannot be negative
    if (R < 0)
        return -1;
 
    // height of the cone
    float h = (4 * R) / 3;
    return h;
}
 
// Driver code
public static void Main()
{
    float R = 10;
 
    Console.WriteLine("r = " + coner(R) +
                      ", " + "h = " + coneh(R));
}
}
 
// This code is contributed
// by Akanksha Rai


Javascript


输出:

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程