mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-08 18:32:56 +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) {
|
public static double volumePyramid(double baseArea, double height) {
|
||||||
return (baseArea * height) / 3;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,5 +32,8 @@ public class VolumeTest {
|
|||||||
|
|
||||||
/* test pyramid */
|
/* test pyramid */
|
||||||
assertTrue(Volume.volumePyramid(10, 3) == 10.0);
|
assertTrue(Volume.volumePyramid(10, 3) == 10.0);
|
||||||
|
|
||||||
|
/* test frustum */
|
||||||
|
assertTrue(Volume.volumeFrustumOfCone(3, 5, 7) == 359.188760060433);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user