vector.h new features (complex-kr) and syntax fixes

Former-commit-id: adc38be811b059f9eca4a119131da7250b709eec
This commit is contained in:
Marek Nečada 2019-06-24 14:57:39 +03:00
parent f9d3d3baa0
commit b8b4497b12
2 changed files with 23 additions and 2 deletions

View File

@ -220,6 +220,11 @@ typedef struct ccart3_t {
complex double x, y, z;
} ccart3_t;
/// 3D complex vector pair (represents the E, H fields).
typedef struct ccart3_pair {
ccart3_t E, H;
} ccart3_pair;
/// 2D cartesian coordinates. See also vectors.h.
/** See also vectors.h */
typedef struct cart2_t {

View File

@ -170,13 +170,16 @@ static inline double cart3_dot(const cart3_t a, const cart3_t b) {
}
static inline csph_t sph_cscale(complex double c, const sph_t s) {
return {c * s.r, s.theta, s.phi};
csph_t res = {c * s.r, s.theta, s.phi};
return res;
}
static inline sph_t sph_scale(double c, const sph_t s) {
return {c * s.r, s.theta, s.phi};
sph_t res = {c * s.r, s.theta, s.phi};
return res;
}
/// Coordinate transform of a vector in local geographic to global cartesian system.
// equivalent to sph_loccart2cart in qpms_p.py
static inline ccart3_t csphvec2ccart(const csphvec_t sphvec, const sph_t at) {
const double st = sin(at.theta);
@ -199,6 +202,19 @@ static inline ccart3_t csphvec2ccart(const csphvec_t sphvec, const sph_t at) {
return res;
}
/// Coordinate transform of a vector in local geographic to global cartesian system.
/**
* Same as csphvec2ccart, but with csph_t as second argument.
* (The radial part (which is the only complex part of csph_t)
* of the second argument does not play role in the
* transformation, so this is completely legit
*/
static inline ccart3_t csphvec2ccart_csph(const csphvec_t sphvec, const csph_t at) {
const sph_t atreal = {0 /*not used*/, at.theta, at.phi};
return csphvec2ccart(sphvec, atreal);
}
/// Coordinate transform of a vector in global cartesian to local geographic system.
static inline csphvec_t ccart2csphvec(const ccart3_t cartvec, const sph_t at) {
// this chunk is copy-pasted from csphvec2cart, so there should be a better way...
const double st = sin(at.theta);