2 * @file hypersphere.tpp
3 * @brief Hypersphere template implementation.
4 * @details Contains the inline implementations of `Hypersphere` methods
5 * for N-dimensional ball volume and containment testing.
9#include "../geometry.hpp"
10#include "integration_domain.hpp"
12namespace mc::domains {
15#define M_PI 3.14159265358979323846
19 * @brief Construct a hypersphere of given radius.
20 * @tparam dim Dimensionality of the space.
21 * @param rad Radius of the hypersphere (must be > 0).
23 * @details Initializes an N-dimensional solid ball centered at the origin
24 * with the specified radius. The ball is closed: ||x|| ≤ rad.
27Hypersphere<dim>::Hypersphere(double rad):
32 * @brief Get the axis-aligned bounding box enclosing the hypersphere.
33 * @tparam dim Dimensionality parameter.
34 * @return Bounds with min/max = ±radius for all dimensions.
36 * @details The minimal axis-aligned bounding box of a hypersphere
37 * is a hypercube [-r, r]^dim. This is used for rejection sampling.
40auto Hypersphere<dim>::getBounds() const -> mc::geom::Bounds<dim> {
41 mc::geom::Bounds<dim> bounds;
42 for(size_t i = 0; i < dim; ++i)
43 bounds[i] = std::make_pair(-radius, radius);
48 * @brief Compute the volume of the bounding hypercube.
49 * @tparam dim Dimensionality parameter.
50 * @return (2*radius)^dim
52 * @details This is the volume of the minimal axis-aligned bounding box,
53 * not the actual hypersphere volume. Used for normalization in Monte Carlo.
54 * The actual ball volume is: V = (π^(n/2) / Γ(n/2 + 1)) * r^n.
57double Hypersphere<dim>::getBoxVolume() const{
58 return std::pow(2 * radius, dim);
62 * @brief Test whether a point lies inside the hypersphere.
63 * @tparam dim Dimensionality parameter.
64 * @param point Point to test.
65 * @return true if ||point|| ≤ radius (point is in the closed ball).
67 * @details Computes the Euclidean norm and tests against the radius.
68 * Time complexity: O(dim) for norm computation.
71bool Hypersphere<dim>::isInside(const mc::geom::Point<dim> &point) const{
73 for(size_t k = 0; k<dim; ++k){
74 norm+=std::pow(point[k], 2);
76 return std::sqrt(norm) <= radius;
79} // namespace mc::domains