Skip to content

Commit b957b1d

Browse files
feat: Add hemi-sphere area algorithm (#2767)
* Add area of hemi-sphere * Update math/area.cpp Co-authored-by: realstealthninja <[email protected]> --------- Co-authored-by: realstealthninja <[email protected]>
1 parent f9fb58f commit b957b1d

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

math/area.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ template <typename T>
109109
T cylinder_surface_area(T radius, T height) {
110110
return 2 * M_PI * radius * height + 2 * M_PI * pow(radius, 2);
111111
}
112+
113+
/**
114+
* @brief surface area of a [hemi-sphere](https://en.wikipedia.org/wiki/Surface_area) ( 3 *
115+
* pi * r^2)
116+
* @param radius is the radius of the hemi-sphere
117+
* @tparam T datatype of radius
118+
* @returns surface area of the hemi-sphere
119+
*/
120+
template <typename T>
121+
T hemi_sphere_surface_area(T radius) {
122+
return 3 * M_PI * pow(radius, 2);
123+
}
112124
} // namespace math
113125

114126
/**
@@ -267,6 +279,18 @@ static void test() {
267279
std::cout << "Output: " << double_area << std::endl;
268280
assert(double_area == double_expected);
269281
std::cout << "TEST PASSED" << std::endl << std::endl;
282+
283+
// 11th test
284+
double_radius = 10.0;
285+
double_expected = 942.4777960769379;
286+
double_area = math::hemi_sphere_surface_area(double_radius);
287+
288+
std::cout << "SURFACE AREA OF A HEMI-SPHERE" << std::endl;
289+
std::cout << "Input Radius: " << double_radius << std::endl;
290+
std::cout << "Expected Output: " << double_expected << std::endl;
291+
std::cout << "Output: " << double_area << std::endl;
292+
assert(double_area == double_expected);
293+
std::cout << "TEST PASSED" << std::endl << std::endl;
270294
}
271295

272296
/**

0 commit comments

Comments
 (0)