Skip to content

Commit 010c955

Browse files
authored
Implement volume calculation for ellipsoid (#7338)
* Implement volume calculation for ellipsoid Added a method to calculate the volume of an ellipsoid. * Add test for volume of ellipsoid * Fix formatting of volumeEllipsoid method * Update Volume.java * Fix precision in ellipsoid volume test * Fix formatting of ellipsoid volume method documentation
1 parent 76c45c1 commit 010c955

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
@@ -125,4 +125,16 @@ public static double volumeFrustumOfPyramid(double upperBaseArea, double lowerBa
125125
public static double volumeTorus(double majorRadius, double minorRadius) {
126126
return 2 * Math.PI * Math.PI * majorRadius * minorRadius * minorRadius;
127127
}
128+
129+
/**
130+
* Calculate the volume of an ellipsoid.
131+
*
132+
* @param a first semi-axis of an ellipsoid
133+
* @param b second semi-axis of an ellipsoid
134+
* @param c third semi-axis of an ellipsoid
135+
* @return volume of the ellipsoid
136+
*/
137+
public static double volumeEllipsoid(double a, double b, double c) {
138+
return (4 * Math.PI * a * b * c) / 3;
139+
}
128140
}

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

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

4242
/* test torus */
4343
assertEquals(39.47841760435743, Volume.volumeTorus(2, 1));
44+
45+
/* test ellipsoid */
46+
assertEquals(25.1327412287183459, Volume.volumeEllipsoid(3, 2, 1));
4447
}
4548
}

0 commit comments

Comments
 (0)