1 #ifndef INCLUDE_AL_SPHERICAL_HPP
2 #define INCLUDE_AL_SPHERICAL_HPP
45 #include "al/math/al_Complex.hpp"
46 #include "al/math/al_Functions.hpp"
47 #include "al/math/al_Vec.hpp"
89 template <
int N,
class T>
109 :
t(theta),
p(phi) {}
123 SphereCoord operator*(T v)
const {
return SphereCoord(
t,
p * v); }
148 tmag != 0 ?
t *= (1. / tmag) :
t.
set(1, 0);
166 template <
int L_MAX = 16>
189 if (m < 0) res.
i = -res.
i;
194 static double coef(
int l,
int m) {
199 static const double&
coefTab(
int l,
int m) {
return LUT(l, m); }
206 return (m < 0 &&
al::odd(M)) ? -res : res;
211 static double& LUT(
int l,
int m) {
212 static double t[L_MAX + 1][L_MAX * 2 + 1];
213 return t[l][m + L_MAX];
216 static void createLUT() {
217 static bool make =
true;
220 for (
int l = 0; l <= L_MAX; ++l) {
221 for (
int m = -L_MAX; m <= L_MAX; ++m) {
224 if (std::abs(m) <= l) c =
coefCalc(l, m);
233 static SphericalHarmonic<> spharm;
240 T rsinp = r * sin(p);
241 T rcosp = r * cos(p);
254 T r = sqrt(x * x + y * y + z * z);
266 template <
int N,
class T>
268 return sub<N - 1>(v) * (T(1) / v[N - 1]);
C & set(T vr, T vi)
Set real and imaginary components.
T mag() const
Returns norm (radius), |z|.
C & fromPolar(T phase)
Set phase and normalize.
Spherical coordinate in terms of two complex numbers.
SphereCoord & fromAngle(const T &theta, const T &phi, const T &radius=T(1))
Set from two angles, in radians, and radius.
SphereCoord operator-() const
Get negation in Cartesian space.
C p
Phi component, latitudinal angle (angle from +z axis)
T radius() const
Get radius.
SphereCoord(const Vec< 3, U > &v)
Vec< 3, T > toCart() const
Returns Cartesian coordinate.
SphereCoord & fromCart(const Vec< 3, U > &v)
Set from Cartesian coordinate.
C t
Theta component, longitudinal angle (angle from +x towards +y)
Spherical harmonic evaluator using cached coefficients.
static double coefCalc(int l, int m)
Get normalization coefficient (calculated)
Complex< T > operator()(int l, int m, const Complex< T > &ctheta, const Complex< T > &cphi) const
Evaluate spherical harmonic.
static const double & coefTab(int l, int m)
Get normalization coefficient (tabulated)
static double coef(int l, int m)
Get normalization coefficient.
Vec3 sterProj(const al::Complex< T > &c)
T powN(T base, unsigned power)
Returns value to a positive integer power.
T legendreP(int l, int m, T t)
double factorialSqrt(int v)
Vec< M, T > sub(const Vec< N, T > &v, int begin=0)
Get a subvector.
SphereCoord< double > SphereCoordd
double SphereCoord
void cartToSpherical(T &x2r, T &y2t, T &z2p)
Convert Cartesian to spherical coordinates in-place.
SphereCoord< float > SphereCoordf
float SphereCoord
void sphericalToCart(T &r2x, T &t2y, T &p2z)
Convert spherical to Cartesian coordinates in-place.