El cono circular recto más grande que se puede inscribir dentro de una esfera que está inscrita dentro de un cubo

Dado un cubo de lado a , que inscribe una esfera que a su vez inscribe un cono circular recto. La tarea es encontrar el mayor volumen posible de este cono.
Ejemplos: 
 

Input:  a = 5
Output: 58.1481

Input: a = 8
Output: 238.175

Aproximación
Sea, la altura del cono circular recto = h
Radio del cono = r 
Radio de la esfera = R 
Sabemos el radio de la esfera dentro del cubo, r = a/2 . Consulte ( Esfera más grande que se puede inscribir dentro de un cubo)
Además, la altura del cono dentro de la esfera, h = 4r/3
radio del cono dentro de la esfera, r = 2√2r/3 . Consulte (El cono circular recto más grande que se puede inscribir dentro de una esfera)
Entonces, altura del cono dentro de la esfera que a su vez está inscrita dentro de un cubo, h = 2a/3
Radio del cono dentro de la esfera que a su vez está inscrita dentro de un cubo, r = √2a/3 .
A continuación se muestra la implementación del enfoque anterior: 
 

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 <bits/stdc++.h>
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

<?php
// PHP 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
 
// Function to find the biggest
// right circular cone
function cone($a)
{
 
    // side cannot be negative
    if ($a < 0)
        return -1;
 
    // radius of right circular cone
    $r = ($a * sqrt(2)) / 3;
 
    // height of right circular cone
    $h = (2 * $a) / 3;
 
    // volume of right circular cone
    $V = 3.14 * pow($r, 2) * $h;
 
    return $V;
}
 
// Driver code
$a = 5;
echo round(cone($a), 4);
 
// This code is contributed by Ryuga
?>

Javascript

<script>
 
// javascript 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
 
// Function to find the biggest right circular cone
function cone(a)
{
 
    // side cannot be negative
    if (a < 0)
        return -1;
 
    // radius of right circular cone
    var r =  (a * Math.sqrt(2)) / 3;
 
    // height of right circular cone
    var h = (2 * a) / 3;
 
    // volume of right circular cone
    var V = (3.14 *Math. pow(r, 2) * h);
 
    return V;
}
 
// Driver code
var a = 5;
document.write( cone(a).toFixed(5));
 
 
// This code is contributed by Amit Katiyar
 
</script>
Producción: 

58.1481

 

Complejidad de tiempo: O(1)

Espacio Auxiliar: O(1)

Publicación traducida automáticamente

Artículo escrito por IshwarGupta y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *