12 #define QPMS_QUAT_ATOL (1e-10)
18 qpms_quat_t q2c = {q.c1 + I * q.ck, q.cj + I * q.ci};
26 qpms_quat4d_t q4d = {creal(q.a), cimag(q.b), creal(q.b), cimag(q.a)};
37 r.a = p.a * q.a - conj(p.b) * q.b;
38 r.b = p.b * q.a + conj(p.a) * q.b;
61 const double vn = sqrt(q4.ci*q4.ci + q4.cj*q4.cj + q4.ck *q4.ck);
62 const double ea = exp(q4.c1);
63 const double cv = vn ? (ea*sin(vn)/vn) : ea;
64 const qpms_quat4d_t r4 = {ea * cos(vn), cv*q4.ci, cv*q4.cj, cv*q4.ck};
91 static inline double qpms_quat_norm(
const qpms_quat_t q) {
92 return sqrt(creal(q.a * conj(q.a) + q.b * conj(q.b)));
108 const double *arr = (
double *) &(p.a);
109 for(
int i = 0; i < 4; ++i)
110 if (fabs(arr[i]) > maxabs + atol) {
112 maxabs = fabs(arr[i]);
129 static inline double qpms_quat_imnorm(
const qpms_quat_t q) {
130 const double z = cimag(q.a), x = cimag(q.b), y = creal(q.b);
131 return sqrt(z*z + x*x + y*y);
136 double n = qpms_quat_norm(q);
137 return qpms_quat_rscale(1/n, q);
142 const double n = qpms_quat_norm(q);
143 const double imnorm = qpms_quat_imnorm(q);
145 const double vc = acos(creal(q.a)/n) / imnorm;
166 const double norm = qpms_quat_norm(q);
167 return qpms_quat_rscale(1./(norm*norm),
180 const cart3_t c = {q4.ci, q4.cj, q4.ck};
186 q = qpms_quat_normalise(q);
197 qpms_quat_from_cart3(v)));
212 complex
double qpms_vswf_irot_elem_from_irot3(
219 static inline int qpms_irot3_checkdet(
const qpms_irot3_t p) {
220 if (p.
det != 1 && p.
det != -1) abort();
227 qpms_irot3_checkdet(p);
228 qpms_irot3_checkdet(q);
237 qpms_irot3_checkdet(p);
246 qpms_irot3_checkdet(p);
249 p.
det == -1 ? min1pow(n) : 1};
255 return qpms_quat_isclose2(p.
rot, q.rot, atol) && p.
det == q.det;
261 qpms_irot3_checkdet(p);
268 static const qpms_irot3_t QPMS_IROT3_IDENTITY = {{1, 0}, 1};
270 static const qpms_irot3_t QPMS_IROT3_XROT_PI = {{0, I}, 1};
272 static const qpms_irot3_t QPMS_IROT3_YROT_PI = {{0, 1}, 1};
274 static const qpms_irot3_t QPMS_IROT3_ZROT_PI = {{I, 0}, 1};
276 static const qpms_irot3_t QPMS_IROT3_INVERSION = {{1, 0}, -1};
278 static const qpms_irot3_t QPMS_IROT3_XFLIP = {{0, I}, -1};
280 static const qpms_irot3_t QPMS_IROT3_YFLIP = {{0, 1}, -1};
282 static const qpms_irot3_t QPMS_IROT3_ZFLIP = {{I, 0}, -1};
285 static inline qpms_quat_t qpms_quat_zrot_angle(
double angle) {
291 static inline qpms_quat_t qpms_quat_zrot_Nk(
double N,
double k) {
292 return qpms_quat_zrot_angle(2 * M_PI * k / N);
296 static inline qpms_irot3_t qpms_irot3_zrot_angle(
double angle) {
302 static inline qpms_irot3_t qpms_irot3_zrot_Nk(
double N,
double k) {
303 return qpms_irot3_zrot_angle(2 * M_PI * k / N);
int qpms_l_t
Type for spherical harmonic degree l.
Definition: qpms_types.h:27
qpms_lm_t qpms_m_t
Type for spherical harmonic order m.
Definition: qpms_types.h:31
Wigner D matrix element from a rotator quaternion for integer a l complex double qpms_wignerD_elem(qpms_quat_t q, qpms_l_t l, qpms_m_t mp, qpms_m_t m)
Definition: wigner.c:6
A VSWF representation element of the qpms_l_t qpms_m_t qpms_m_t bool pseudo
< Determines the sign of improper rotations. True for magnetic waves, false otherwise.
Definition: quaternions.h:216
static qpms_quat_t qpms_quat_add(qpms_quat_t p, qpms_quat_t q)
Quaternion addition.
Definition: quaternions.h:43
A VSWF representation element of the qpms_l_t l
< The O(3) element in the quaternion representation.
Definition: quaternions.h:214
static qpms_quat_t qpms_quat_mult(qpms_quat_t p, qpms_quat_t q)
Quaternion multiplication.
Definition: quaternions.h:35
static qpms_quat_t qpms_quat_sub(qpms_quat_t p, qpms_quat_t q)
Quaternion substraction.
Definition: quaternions.h:51
static qpms_quat_t qpms_quat_2c_from_4d(qpms_quat4d_t q)
Conversion from the 4*double to the 2*complex quaternion.
Definition: quaternions.h:17
static qpms_quat4d_t qpms_quat_4d_from_2c(qpms_quat_t q)
Conversion from the 2*complex to the 4*double quaternion.
Definition: quaternions.h:25
Standardises a quaternion to have the largest component static positive qpms_quat_t qpms_quat_standardise(qpms_quat_t p, double atol)
Definition: quaternions.h:104
Quaternion static inversion qpms_quat_t qpms_quat_inv(const qpms_quat_t q)
Definition: quaternions.h:165
static qpms_quat_t qpms_quat_exp(const qpms_quat_t q)
Exponential function of a quaternion.
Definition: quaternions.h:59
3D cartesian coordinates. See also vectors.h.
Definition: qpms_types.h:186
3D improper rotations represented as a quaternion and a sign of the determinant.
Definition: qpms_types.h:275
short det
Determinant of the transformation (valid values are 1 (rotation) or -1 (improper rotation)
Definition: qpms_types.h:277
qpms_quat_t rot
Quaternion representing the rotation part.
Definition: qpms_types.h:276
Quaternion type as four doubles.
Definition: qpms_types.h:268
Quaternion type.
Definition: qpms_types.h:261
Simple but frequently used inline functions and macros.
Coordinate transforms and vector arithmetics.
static cart3_t cart3_scale(const double c, const cart3_t v)
3D vector scaling
Definition: vectors.h:185