From 0a6aae0776f658be129b073c7407556fa68076ac Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 31 Mar 2020 20:06:37 +0200 Subject: [PATCH] added area_auto and wvolarea_auto functions --- hyperpoint.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hyperpoint.cpp b/hyperpoint.cpp index 7e81e528..97c83d8d 100644 --- a/hyperpoint.cpp +++ b/hyperpoint.cpp @@ -234,6 +234,7 @@ EX ld acos_auto(ld x) { } } +/** \brief volume of a three-dimensional ball of radius r in the current isotropic geometry */ EX ld volume_auto(ld r) { switch(cgclass) { case gcEuclid: return 4 * r * r * r / 3 * M_PI; @@ -243,6 +244,22 @@ EX ld volume_auto(ld r) { } } +/** \brief area of a circle of radius r in the current isotropic geometry */ +EX ld area_auto(ld r) { + switch(cgclass) { + case gcEuclid: return r * r * M_PI; + case gcHyperbolic: return 2 * M_PI * (cosh(r) - 1); + case gcSphere: return 2 * M_PI * (1 - cos(r)); + default: return 0; + } + } + +/** \brief volume in 3D, area in 2D */ +EX ld wvolarea_auto(ld r) { + if(WDIM == 3) return volume_auto(r); + else return area_auto(r); + } + EX ld asin_clamp(ld x) { return x>1 ? M_PI/2 : x<-1 ? -M_PI/2 : std::isnan(x) ? 0 : asin(x); } EX ld asin_auto_clamp(ld x) {