QPMS
Electromagnetic multiple scattering library and toolkit.
Macros | Typedefs | Functions | Variables
vectors.h File Reference

Coordinate transforms and vector arithmetics. More...

#include <math.h>
#include "qpms_types.h"
#include "qpms_error.h"
Include dependency graph for vectors.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define M_PI_2   (1.570796326794896619231321691639751442098584699687552910487)
 

Typedefs

typedef double matrix3d[3][3]
 
typedef double matrix2d[2][2]
 
typedef complex double cmatrix3d[3][3]
 
typedef complex double cmatrix2d[2][2]
 

Functions

static cart2_t cart2_add (const cart2_t a, const cart2_t b)
 2D vector addition.
 
static cart2_t cart2_substract (const cart2_t a, const cart2_t b)
 2D vector substraction.
 
static cart2_t cart2_scale (const double c, const cart2_t v)
 2D vector scaling.
 
static double cart2_dot (const cart2_t a, const cart2_t b)
 2D vector dot product.
 
static double cart2_normsq (const cart2_t a)
 
static double cart2norm (const cart2_t v)
 2D vector euclidian norm.
 
static pol_t cart2pol (const cart2_t cart)
 2D cartesian to polar coordinates conversion. See Coordinate systems and default conversions.
 
static sph_t pol2sph_equator (const pol_t pol)
 Polar to spherical coordinates conversion. See Coordinate systems and default conversions.
 
static sph_t cart22sph (const cart2_t cart)
 2D cartesian to spherical coordinates conversion. See Coordinate systems and default conversions.
 
static sph_t cart12sph_zaxis (double z)
 1D cartesian to spherical coordinates conversion. See Coordinate systems and default conversions.
 
static cart3_t cart12cart3z (double z)
 1D to 3D cartesian coordinates conversion. See Coordinate systems and default conversions.
 
static cart3_t cart22cart3xy (const cart2_t a)
 2D to 3D cartesian coordinates conversion. See Coordinate systems and default conversions.
 
static cart2_t cart3xy2cart2 (const cart3_t a)
 
static double cart3_dot (const cart3_t a, const cart3_t b)
 3D vector dot product.
 
static cart3_t cart3_vectorprod (const cart3_t a, const cart3_t b)
 3D vector product a.k.a. cross product.
 
static double cart3_tripleprod (const cart3_t a, const cart3_t b, const cart3_t c)
 Scalar triple product \( a \cdot ( b \times c ) \).
 
static double cart3_normsq (const cart3_t a)
 3D vector euclidian norm squared.
 
static double cart3norm (const cart3_t v)
 3D vector euclidian norm.
 
static sph_t cart2sph (const cart3_t cart)
 3D cartesian to spherical coordinates conversion. See Coordinate systems and default conversions.
 
static cart3_t sph2cart (const sph_t sph)
 Spherical to 3D cartesian coordinates conversion. See Coordinate systems and default conversions.
 
static cart2_t pol2cart (const pol_t pol)
 Polar to 2D cartesian coordinates conversion. See Coordinate systems and default conversions.
 
static cart3_t pol2cart3_equator (const pol_t pol)
 Polar to 3D cartesian coordinates conversion. See Coordinate systems and default conversions.
 
static cart3_t cart3_add (const cart3_t a, const cart3_t b)
 3D vector addition.
 
static cart3_t cart3_substract (const cart3_t a, const cart3_t b)
 3D vector substraction.
 
static cart3_t cart3_scale (const double c, const cart3_t v)
 3D vector scaling
 
static cart3_t cart3_divscale (const cart3_t v, const double c)
 3D vector division by scalar (N.B. argument order).
 
static double cart3_dist (const cart3_t a, const cart3_t b)
 Euclidian distance between two 3D points.
 
static bool cart3_isclose (const cart3_t a, const cart3_t b, double rtol, double atol)
 
static ccart3_t ccart3_scale (const complex double c, const ccart3_t v)
 Complex 3D vector scaling.
 
static ccart3_t ccart3_add (const ccart3_t a, const ccart3_t b)
 Complex 3D vector adition.
 
static ccart3_t ccart3_substract (const ccart3_t a, const ccart3_t b)
 Complex 3D vector substraction.
 
static complex double ccart3_dotnc (const ccart3_t a, const ccart3_t b)
 Complex 3D cartesian vector "dot product" without conjugation.
 
static ccart3_t cart32ccart3 (cart3_t c)
 Convert cart3_t to ccart3_t.
 
static csphvec_t csphvec_add (const csphvec_t a, const csphvec_t b)
 Complex 3D vector (geographic coordinates) addition.
 
static csphvec_t csphvec_substract (const csphvec_t a, const csphvec_t b)
 Complex 3D vector (geographic coordinates) substraction.
 
static csphvec_t csphvec_scale (complex double c, const csphvec_t v)
 Complex 3D vector (geographic coordinates) scaling.
 
static complex double csphvec_dotnc (const csphvec_t a, const csphvec_t b)
 Complex 3D vector (geographic coordinates) "dot product" without conjugation.
 
static sph_t sph_scale (double c, const sph_t s)
 Spherical coordinate system scaling.
 
static csph_t sph_cscale (complex double c, const sph_t s)
 "Complex spherical" coordinate system scaling.
 
static ccart3_t csphvec2ccart (const csphvec_t sphvec, const sph_t at)
 Coordinate transform of a vector in local geographic to global cartesian system.
 
static ccart3_t csphvec2ccart_csph (const csphvec_t sphvec, const csph_t at)
 Coordinate transform of a vector in local geographic to global cartesian system. More...
 
static csphvec_t ccart2csphvec (const ccart3_t cartvec, const sph_t at)
 Coordinate transform of a vector in global cartesian to local geographic system.
 
static csph_t sph2csph (sph_t s)
 Convert sph_t to csph_t.
 
static sph_t csph2sph (csph_t s)
 Convert csph_t to sph_t, discarding the imaginary part of radial component.
 
static csph_t ccart2csph (const ccart3_t cart)
 Lossy coordinate transform of ccart3_t to csph_t. More...
 
static csph_t cart2csph (const cart3_t cart)
 Real 3D cartesian to spherical (complex r) coordinates conversion. See Coordinate systems and default conversions.
 
static ccart3_t csph2ccart (const csph_t sph)
 Coordinate transform of csph_t to ccart3_t.
 
void print_csphvec (csphvec_t)
 
void print_ccart3 (ccart3_t)
 
void print_cart3 (cart3_t)
 
void print_sph (sph_t)
 
static void ccart3_kahaninit (ccart3_t *sum, ccart3_t *compensation)
 Kanan sum initialisation for ccart3_t.
 
static void csphvec_kahaninit (csphvec_t *sum, csphvec_t *compensation)
 Kanan sum initialisation for csphvec_t.
 
static void ccart3_kahanadd (ccart3_t *sum, ccart3_t *compensation, const ccart3_t input)
 Add element to Kahan sum (ccart3_t).
 
static void csphvec_kahanadd (csphvec_t *sum, csphvec_t *compensation, const csphvec_t input)
 Add element to Kahan sum (csphvec_t).
 
static double csphvec_norm (const csphvec_t a)
 Euclidian norm of a vector in geographic coordinates.
 
static double csphvec_reldiff_abstol (const csphvec_t a, const csphvec_t b, double tolerance)
 
static double csphvec_reldiff (const csphvec_t a, const csphvec_t b)
 
static sph_t anycoord2sph (anycoord_point_t p, qpms_coord_system_t t)
 Conversion from anycoord_point_t to explicitly spherical coordinates. More...
 
static cart3_t anycoord2cart3 (anycoord_point_t p, qpms_coord_system_t t)
 Conversion from anycoord_point_t to explicitly 3D cartesian coordinates. More...
 
static double anycoord_norm (anycoord_point_t p, qpms_coord_system_t t)
 Cartesian norm of anycoord_point_t.
 
static pol_t anycoord2pol (anycoord_point_t p, qpms_coord_system_t t)
 Conversion from anycoord_point_t to explicitly polar coordinates. More...
 
static cart2_t anycoord2cart2 (anycoord_point_t p, qpms_coord_system_t t)
 Conversion from anycoord_point_t to explicitly 2D cartesian coordinates. More...
 
static double anycoord2cart1 (anycoord_point_t p, qpms_coord_system_t t)
 Conversion from anycoord_point_t to explicitly 1D cartesian coordinates. More...
 
static void qpms_array_coord_transform (void *dest, qpms_coord_system_t tdest, const void *src, qpms_coord_system_t tsrc, size_t nmemb)
 Coordinate conversion of point arrays (something to something). More...
 
static void anycoord_arr2something (void *dest, qpms_coord_system_t tdest, const anycoord_point_t *src, qpms_coord_system_t tsrc, size_t nmemb)
 Coordinate conversion of point arrays (anycoord_point_t to something). More...
 
static void cart3_to_double_array (double a[], cart3_t b)
 Converts cart3_t to array of doubles.
 
static cart3_t cart3_from_double_array (const double a[])
 Converts array of doubles to cart3_t.
 
static void cart2_to_double_array (double a[], cart2_t b)
 Converts cart2_t to array of doubles.
 
static cart2_t cart2_from_double_array (const double a[])
 Converts array of doubles to cart2_t.
 

Variables

static const cart2_t CART2_ZERO = {0, 0}
 
static const cart3_t CART3_ZERO = {0, 0, 0}
 

Detailed Description

Coordinate transforms and vector arithmetics.

Function Documentation

◆ anycoord2cart1()

static double anycoord2cart1 ( anycoord_point_t  p,
qpms_coord_system_t  t 
)
inlinestatic

Conversion from anycoord_point_t to explicitly 1D cartesian coordinates.

See Coordinate systems and default conversions for the conversion definitions.

◆ anycoord2cart2()

static cart2_t anycoord2cart2 ( anycoord_point_t  p,
qpms_coord_system_t  t 
)
inlinestatic

Conversion from anycoord_point_t to explicitly 2D cartesian coordinates.

See Coordinate systems and default conversions for the conversion definitions.

◆ anycoord2cart3()

static cart3_t anycoord2cart3 ( anycoord_point_t  p,
qpms_coord_system_t  t 
)
inlinestatic

Conversion from anycoord_point_t to explicitly 3D cartesian coordinates.

See Coordinate systems and default conversions for the conversion definitions.

◆ anycoord2pol()

static pol_t anycoord2pol ( anycoord_point_t  p,
qpms_coord_system_t  t 
)
inlinestatic

Conversion from anycoord_point_t to explicitly polar coordinates.

See Coordinate systems and default conversions for the conversion definitions.

◆ anycoord2sph()

static sph_t anycoord2sph ( anycoord_point_t  p,
qpms_coord_system_t  t 
)
inlinestatic

Conversion from anycoord_point_t to explicitly spherical coordinates.

See Coordinate systems and default conversions for the conversion definitions.

◆ anycoord_arr2something()

static void anycoord_arr2something ( void *  dest,
qpms_coord_system_t  tdest,
const anycoord_point_t src,
qpms_coord_system_t  tsrc,
size_t  nmemb 
)
inlinestatic

Coordinate conversion of point arrays (anycoord_point_t to something).

The dest and src arrays must not overlap

◆ ccart2csph()

static csph_t ccart2csph ( const ccart3_t  cart)
inlinestatic

Lossy coordinate transform of ccart3_t to csph_t.

The angle and real part of the radial coordinate are determined from the real components of \cart . The imaginary part of the radial coordinate is then determined as the length of the imaginary part of cart projected onto the real part of cart.

N.B. this obviously makes not much sense for purely imaginary vectors (and will cause NANs). TODO handle this better, as purely imaginary vectors could make sense e.g. for evanescent waves.

◆ csphvec2ccart_csph()

static ccart3_t csphvec2ccart_csph ( const csphvec_t  sphvec,
const csph_t  at 
)
inlinestatic

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

◆ qpms_array_coord_transform()

static void qpms_array_coord_transform ( void *  dest,
qpms_coord_system_t  tdest,
const void *  src,
qpms_coord_system_t  tsrc,
size_t  nmemb 
)
inlinestatic

Coordinate conversion of point arrays (something to something).

The dest and src arrays must not overlap