Largest right circular cone that can be inscribed within a sphere
Last Updated :
27 Aug, 2022
Given sphere of radius . The task is to find the radius of base and height of the largest right circular cone that can be inscribed within it.
Examples:
Input : R = 10
Output : r = 9.42809, h = 13.3333
Input : R = 25
Output : r = 23.5702, h = 33.3333
Approach:
Let the radius of the cone = r
height of the cone = h
From the diagram it is clear that:
x = ?(R^2 – r^2) and h=x+R
Now using these values we get,
To maximize the volume of the cone(V):
V = (?r2h)/3
From the diagram,
V = (?r2R)/3 + ?r2?(R2 – r2)/3
Taking first derivative of V with respect to r we get,
Now, setting dV/dr = 0 we get,
Squaring both sides and solving we get,
since, h = R + ?(R2 – r2)
Now calculating the second derivative we get
Thus r=(2R?2)/3 is point of maxima
So, h = 4R/3
Below is the implementation of the above approach:
C++
#include <bits/stdc++.h>
using namespace std;
float coner( float R)
{
if (R < 0)
return -1;
float r = (2 * sqrt (2) * R) / 3;
return r;
}
float coneh( float R)
{
if (R < 0)
return -1;
float h = (4 * R) / 3;
return h;
}
int main()
{
float R = 10;
cout << "r = " << coner(R) << ", "
<< "h = " << coneh(R) << endl;
return 0;
}
|
Java
import java.util.*;
import java.lang.*;
class GFG
{
static float coner( float R)
{
if (R < 0 )
return - 1 ;
float r = ( float )( 2 *
Math.sqrt( 2 ) * R) / 3 ;
return r;
}
static float coneh( float R)
{
if (R < 0 )
return - 1 ;
float h = ( 4 * R) / 3 ;
return h;
}
public static void main(String args[])
{
float R = 10 ;
System.out.println( "r = " + coner(R) +
", " + "h = " + coneh(R));
}
}
|
Python3
import math
def coner(R):
if (R < 0 ):
return - 1 ;
r = ( 2 * math.sqrt( 2 ) * R) / 3
return float (r)
def coneh(R):
if (R < 0 ):
return - 1 ;
h = ( 4 * R) / 3
return float (h)
R = 10
print ( "r = " , coner(R) ,
", " , "h = " , coneh(R))
|
C#
using System;
class GFG
{
static float coner( float R)
{
if (R < 0)
return -1;
float r = ( float )(2 *
Math.Sqrt(2) * R) / 3;
return r;
}
static float coneh( float R)
{
if (R < 0)
return -1;
float h = (4 * R) / 3;
return h;
}
public static void Main()
{
float R = 10;
Console.WriteLine( "r = " + coner(R) +
", " + "h = " + coneh(R));
}
}
|
PHP
<?php
function coner( $R )
{
if ( $R < 0)
return -1;
$r = (2 * sqrt(2) * $R ) / 3;
return $r ;
}
function coneh( $R )
{
if ( $R < 0)
return -1;
$h = (4 * $R ) / 3;
return $h ;
}
$R = 10;
echo ( "r = " );
echo coner( $R );
echo ( ", " );
echo ( "h = " );
echo (coneh( $R ));
?>
|
Javascript
<script>
function coner(R)
{
if (R < 0)
return -1;
var r = (2 *
Math.sqrt(2) * R) / 3;
return r;
}
function coneh(R)
{
if (R < 0)
return -1;
var h = (4 * R) / 3;
return h;
}
var R = 10;
document.write( "r = " + coner(R).toFixed(5) +
", " + "h = " + coneh(R).toFixed(5));
</script>
|
Output: r = 9.42809, h = 13.3333
Time Complexity: O(1)
Auxiliary Space: O(1), since no extra space has been taken.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...