Added volume of a pyramid frustum (#7291)

* Added volume of a pyramid frustum

Added a function calculating volume of a pyramid frustum, V=(S1+S2+sqrt(S1*S2))*h/3

* compiler error fixed

* Added pyramid frustum test case

* extra space removed
This commit is contained in:
kvadrik
2026-02-27 23:35:42 +02:00
committed by GitHub
parent 7e5d9d469d
commit 705eb52833
2 changed files with 15 additions and 0 deletions

View File

@@ -102,4 +102,16 @@ public final class Volume {
public static double volumeFrustumOfCone(double r1, double r2, double height) {
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
}
/**
* Calculate the volume of a frustum of a pyramid.
*
* @param upperBaseArea area of the upper base
* @param lowerBaseArea area of the lower base
* @param height height of the frustum
* @return volume of the frustum
*/
public static double volumeFrustumOfPyramid(double upperBaseArea, double lowerBaseArea, double height) {
return (upperBaseArea + lowerBaseArea + Math.sqrt(upperBaseArea * lowerBaseArea)) * height / 3;
}
}

View File

@@ -35,5 +35,8 @@ public class VolumeTest {
/* test frustum */
assertEquals(359.188760060433, Volume.volumeFrustumOfCone(3, 5, 7));
/* test pyramid frustum */
assertEquals(140.0, Volume.volumeFrustumOfPyramid(6, 24, 10));
}
}