Skip to content

Commit 3cb5a48

Browse files
authored
Merge branch 'master' into mcoloring_improvement
2 parents 29de3d5 + 7c56a73 commit 3cb5a48

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,16 @@ public static double volumePrism(double baseArea, double height) {
9090
public static double volumePyramid(double baseArea, double height) {
9191
return (baseArea * height) / 3;
9292
}
93+
94+
/**
95+
* Calculate the volume of a frustum of a cone.
96+
*
97+
* @param r1 radius of the top of the frustum
98+
* @param r2 radius of the bottom of the frustum
99+
* @param height height of the frustum
100+
* @return volume of the frustum
101+
*/
102+
public static double volumeFrustumOfCone(double r1, double r2, double height) {
103+
return (Math.PI * height / 3) * (r1 * r1 + r2 * r2 + r1 * r2);
104+
}
93105
}

src/test/java/com/thealgorithms/maths/VolumeTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ public void volume() {
3232

3333
/* test pyramid */
3434
assertTrue(Volume.volumePyramid(10, 3) == 10.0);
35+
36+
/* test frustum */
37+
assertTrue(Volume.volumeFrustumOfCone(3, 5, 7) == 359.188760060433);
3538
}
3639
}

0 commit comments

Comments
 (0)