Chi-Tech
chi_math_01_utility.cc
Go to the documentation of this file.
1#include "chi_math.h"
2
3//###################################################################
4/**Computes the factorial of an integer.*/
5double chi_math::Factorial(const int x)
6{
7 double factorial_value = 1.0;
8 for (int i=2; i<=x; ++i)
9 factorial_value *= i;
10
11 return factorial_value;
12}
13
14//###################################################################
15/**Determines the azimuthal- and polar-angle associated with
16 * the given direction vector.
17 * Returns a pair = [azimuthal-angle,polar-angle].*/
18std::pair<double,double> chi_math::
20{
21 // Notes: asin maps [-1,+1] to [-pi/2,+pi/2]
22 // acos maps [-1,+1] to [0,pi]
23 // This mapping requires some logic for determining the azimuthal angle.
24 //
25 const auto omega_hat = omega.Normalized();
26
27 double mu = omega_hat.z;
28 mu = std::min(mu, 1.0);
29 mu = std::max(mu, -1.0);
30
31 double theta = acos(mu);
32
33 //===== Handling omega aligned to k_hat
34 if (std::fabs(omega_hat.z) < 1.0e-16) return {0.0,theta};
35
36 double cos_phi = omega_hat.x/sin(theta);
37 cos_phi = std::min(cos_phi, 1.0);
38 cos_phi = std::max(cos_phi, -1.0);
39
40 //===== Computing varphi for NE and NW quadrant
41 if (omega_hat.y >= 0.0)
42 return {acos(cos_phi), theta};
43 //===== Computing varphi for SE and SW quadrant
44 else
45 return {2.0*M_PI - acos(cos_phi), theta};
46
47}
48
49
std::pair< double, double > OmegaToPhiThetaSafe(const chi_mesh::Vector3 &omega)
double Factorial(int x)
Vector3 Normalized() const
double z
Element-2.