mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 10:15:51 +08:00
Add Volume "Algorithm Frustum Of Cone" Then Test It. (#5479)
* Add Function volumeFrustum To Calculate Frustum Of Cone Then Test It. * Add Function volumeFrustumOfCone To Calculate Frustum Of Cone Then Test It. * Update VolumeTest.java * Update Volume.java
This commit is contained in:
@ -90,4 +90,16 @@ public final class Volume {
|
||||
public static double volumePyramid(double baseArea, double height) {
|
||||
return (baseArea * height) / 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the volume of a frustum of a cone.
|
||||
*
|
||||
* @param r1 radius of the top of the frustum
|
||||
* @param r2 radius of the bottom of the frustum
|
||||
* @param height height of the frustum
|
||||
* @return volume of the frustum
|
||||
*/
|
||||
public static double volumeFrustumOfCone(double r1, double r2, double height) {
|
||||
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user