# Largest right circular cone that can be inscribed within a sphere

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 = 10Output: r = 9.42809, h = 13.3333Input: R = 25Output: 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)**

Now,

To maximize the volume of the cone(V):

V = (πr^{2}h)/3From the diagram,

V = (πr^{2}R)/3 + πr^{2}√(R^{2>}– r^{2})/3Taking derivative of

Vwith respect torwe get,

dV/dr = 2πr(√(R^{2}– r^{2}) + R)/3 – πr^{2}√(R^{2}– r^{2})/3Now, setting

dV/dr = 0we get,

r = 2√2R/3since,

h = R + √(R^{2}– r^{2})So,

h = 4R/3

Below is the implementation of the above approach:

## C++

`// C++ Program to find the biggest cone ` `// that can be inscribed within a sphere ` `#include <bits/stdc++.h> ` `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; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// 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 ` |

*chevron_right*

*filter_none*

## Python3

# 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
[tabby title="C#"]

`// 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 ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP Program to find the biggest ` `// cone that can be inscribed ` `// within a sphere ` ` ` `// Function to find the radius ` `// of the cone ` `function` `coner(` `$R` `) ` `{ ` ` ` ` ` `// radius cannot be negative ` ` ` `if` `(` `$R` `< 0) ` ` ` `return` `-1; ` ` ` ` ` `// radius of the cone ` ` ` `$r` `= (2 * sqrt(2) * ` `$R` `) / 3; ` ` ` `return` `$r` `; ` `} ` ` ` `// Function to find the height ` `// of the cone ` `function` `coneh(` `$R` `) ` `{ ` ` ` ` ` `// side cannot be negative ` ` ` `if` `(` `$R` `< 0) ` ` ` `return` `-1; ` ` ` ` ` `// height of the cone ` ` ` `$h` `= (4 * ` `$R` `) / 3; ` ` ` `return` `$h` `; ` `} ` ` ` `// Driver code ` `$R` `= 10; ` ` ` `echo` `(` `"r = "` `); ` `echo` `coner(` `$R` `); ` `echo` `(` `", "` `); ` `echo` `(` `"h = "` `); ` `echo` `(coneh(` `$R` `)); ` ` ` `// This code is contributed ` `// by Shivi_Aggarwal ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

r = 9.42809, h = 13.3333

## Recommended Posts:

- Largest sphere that can be inscribed within a cube which is in turn inscribed within a right circular cone
- Largest right circular cone that can be inscribed within a sphere which is inscribed within a cube
- Largest right circular cylinder that can be inscribed within a cone which is in turn inscribed within a cube
- Largest sphere that can be inscribed in a right circular cylinder inscribed in a frustum
- Largest cube that can be inscribed within a right circular cone
- Largest right circular cylinder that can be inscribed within a cone
- Largest cone that can be inscribed within a cube
- Largest cube that can be inscribed within the sphere
- Largest sphere that can be inscribed inside a cube
- Volume of largest right circular cylinder within a Sphere
- Largest cube that can be inscribed within a right circular cylinder
- Largest ellipse that can be inscribed within a rectangle which in turn is inscribed within a semicircle
- Largest square that can be inscribed within a hexagon which is inscribed within an equilateral triangle
- Volume of biggest sphere within a right circular cylinder
- Largest triangle that can be inscribed in an ellipse

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.