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>
This commit is contained in:
Harshil Shah
2024-10-07 06:15:29 +05:30
committed by GitHub
parent f9fb58fb87
commit b957b1dfef

View File

@@ -109,6 +109,18 @@ template <typename T>
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 <typename T>
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;
}
/**