Skip to content

Commit 7b653b9

Browse files
Merge branch 'master' into patch-2
2 parents 12131e7 + 0d2a98e commit 7b653b9

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-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
@@ -114,4 +114,15 @@ public static double volumeFrustumOfCone(double r1, double r2, double height) {
114114
public static double volumeFrustumOfPyramid(double upperBaseArea, double lowerBaseArea, double height) {
115115
return (upperBaseArea + lowerBaseArea + Math.sqrt(upperBaseArea * lowerBaseArea)) * height / 3;
116116
}
117+
118+
/**
119+
* Calculate the volume of a torus.
120+
*
121+
* @param majorRadius major radius of a torus
122+
* @param minorRadius minor radius of a torus
123+
* @return volume of the torus
124+
*/
125+
public static double volumeTorus(double majorRadius, double minorRadius) {
126+
return 2 * Math.PI * Math.PI * majorRadius * minorRadius * minorRadius;
127+
}
117128
}

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

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

3939
/* test pyramid frustum */
4040
assertEquals(140.0, Volume.volumeFrustumOfPyramid(6, 24, 10));
41+
42+
/* test torus */
43+
assertEquals(39.47841760435743, Volume.volumeTorus(2, 1));
4144
}
4245
}

0 commit comments

Comments
 (0)