Skip to content

Commit e99871f

Browse files
authored
Added volume of a pyramid frustum
Added a function calculating volume of a pyramid frustum, V=(S1+S2+sqrt(S1*S2))*h/3
1 parent 7e5d9d4 commit e99871f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/com/thealgorithms/maths/Volume.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,15 @@ public static double volumePyramid(double baseArea, double height) {
102102
public static double volumeFrustumOfCone(double r1, double r2, double height) {
103103
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
104104
}
105+
106+
/**
107+
* Calculate the volume of a frustum of a pyramid.
108+
*
109+
* @param upperBaseArea area of the upper base
110+
* @param lowerBaseArea area of the lower base
111+
* @param height height of the frustum
112+
* @return volume of the frustum
113+
*/
114+
public static double volumeFrustumOfPyramid(double upperBaseArea, double lowerBaseArea, double height) {
115+
return (upperBaseArea + lowerBaseArea + Math.sqrt(upperBaseArea * lowerBaseArea)) * height / 3;
105116
}

0 commit comments

Comments
 (0)