From b957b1dfef9f13eb85182b92ba7d294301e8d1ca Mon Sep 17 00:00:00 2001 From: Harshil Shah <143382356+HarshilShah1804@users.noreply.github.com> Date: Mon, 7 Oct 2024 06:15:29 +0530 Subject: [PATCH] feat: Add hemi-sphere area algorithm (#2767) * Add area of hemi-sphere * Update math/area.cpp Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --------- Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com> --- math/area.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/math/area.cpp b/math/area.cpp index 691fe91f0fc..a787e2e3a45 100644 --- a/math/area.cpp +++ b/math/area.cpp @@ -109,6 +109,18 @@ template T cylinder_surface_area(T radius, T height) { return 2 * M_PI * radius * height + 2 * M_PI * pow(radius, 2); } + +/** + * @brief surface area of a [hemi-sphere](https://en.wikipedia.org/wiki/Surface_area) ( 3 * + * pi * r^2) + * @param radius is the radius of the hemi-sphere + * @tparam T datatype of radius + * @returns surface area of the hemi-sphere + */ +template +T hemi_sphere_surface_area(T radius) { + return 3 * M_PI * pow(radius, 2); +} } // namespace math /** @@ -267,6 +279,18 @@ static void test() { std::cout << "Output: " << double_area << std::endl; assert(double_area == double_expected); std::cout << "TEST PASSED" << std::endl << std::endl; + + // 11th test + double_radius = 10.0; + double_expected = 942.4777960769379; + double_area = math::hemi_sphere_surface_area(double_radius); + + std::cout << "SURFACE AREA OF A HEMI-SPHERE" << std::endl; + std::cout << "Input Radius: " << double_radius << std::endl; + std::cout << "Expected Output: " << double_expected << std::endl; + std::cout << "Output: " << double_area << std::endl; + assert(double_area == double_expected); + std::cout << "TEST PASSED" << std::endl << std::endl; } /**