Vector.h more convenience inlines

Former-commit-id: 4e0b0331fdb50192e9518d017f6bbc46fdf1fe1b
This commit is contained in:
Marek Nečada 2019-07-14 23:55:45 +03:00
parent 8eb0f9f2ea
commit 02a8161d3e
1 changed files with 8 additions and 1 deletions

View File

@ -293,6 +293,12 @@ static inline csph_t sph2csph(sph_t s) {
return cs; return cs;
} }
/// Convert csph_t to sph_t, discarding the imaginary part of radial component.
static inline sph_t csph2sph(csph_t s) {
sph_t rs = {creal(s.r), s.theta, s.phi};
return rs;
}
/// Lossy coordinate transform of ccart3_t to csph_t. /// Lossy coordinate transform of ccart3_t to csph_t.
/** The angle and real part of the radial coordinate are determined /** The angle and real part of the radial coordinate are determined
* from the real components of \a \cart. The imaginary part of the radial * from the real components of \a \cart. The imaginary part of the radial
@ -300,7 +306,8 @@ static inline csph_t sph2csph(sph_t s) {
* part of \a cart *projected onto* the real part of \a cart. * part of \a cart *projected onto* the real part of \a cart.
* *
* N.B. this obviously makes not much sense for purely imaginary vectors * N.B. this obviously makes not much sense for purely imaginary vectors
* (and will cause NANs). TODO handle this better. * (and will cause NANs). TODO handle this better, as purely imaginary
* vectors could make sense e.g. for evanescent waves.
*/ */
static inline csph_t ccart2csph(const ccart3_t cart) { static inline csph_t ccart2csph(const ccart3_t cart) {
cart3_t rcart = {creal(cart.x), creal(cart.y), creal(cart.z)}; cart3_t rcart = {creal(cart.x), creal(cart.y), creal(cart.z)};