File numerics/src/tools/op3x3.h

Go to the source code of this file

linear algebra operations in 3D

Defines

A(y, x)
M_PI
M_PI_2
mat_elem(a, y, x, n)
MAYBE_UNUSED
OP3(EXPR)

OP3(EXPR) do EXPR 3 times.

Parameters
  • EXPR: a C expression that should contains self incrementing pointers on arrays[9]

OP3X3(EXPR)

OP3X3(EXPR) do EXPR 9 times.

Parameters
  • EXPR: a C expression that should contains self incrementing pointers on arrays[9]

SET3(V)

SET3 : set pointers on a vector3 v (*v0 *v1 *v2) Warning: the pointer v is modified and is ready for a next SET3 use *v0 if you need *v.

SET3MAYBE(V)

SET3MAYBE : set pointers on a vector3 v (*v0 *v1 *v2) only if v is non null.

Warning: the pointer v is modified and is ready for a next SET3 use *v0 if you need *v

SET3X3(V)

SET3X3 : set pointers on a 3x3 matrix a (*a00 *a01 *a10 etc.) warning the pointer a is modified (use a00 instead) and is ready for a next SET3X3.

SET3X3MAYBE(V)
SOLVE_3X3_GEPP(MAT, X)
WARN_RESULT_IGNORED

Functions

static void add3(double a[3], double b[3])

add a vector[3]

Parameters
  • [in] a: a[3]

  • [inout] b: b[3]

static void add3x3(double a[9], double b[9])

add a 3x3 matrix or a vector[9]

Parameters
  • [in] a: a[9]

  • [inout] b: b[9]

static void cpy3(double a[3], double b[3])

copy a vector[3]

Parameters
  • [in] a: a[3]

  • [out] b: b[3]

static void cpy3x3(double *restrict a, double *restrict b)

copy a 3x3 matrix or a vector[9]

Parameters
  • [in] a: a[9]

  • [out] b: b[9]

static void cpytr3x3(double *restrict a, double *restrict b)

copy & transpose a matrix

Parameters
  • [in] a: *a

  • [out] b: transpose(*a)

static void cross3(double *restrict a, double *restrict b, double *restrict c)

cross product : c <- a x b

Parameters
  • [in] a: double a[3]

  • [in] b: double b[3]

  • [out] c: double c[3]

static double det3x3(double *a)

determinant

Return

the value of the determinant

Parameters
  • [in] a: double* a

static void diag_scal3(double *restrict scal_coeffs, double *restrict v)

diagonal scaling of a vector

Parameters
  • [in] scal_coeffs: diagonal part of a matrix

  • [inout] v: a 3D vector

static double dot3(double *restrict a, double *restrict b)

scalar product : c <- a.b

Return

the scalar product

Parameters
  • [in] a: double a[3]

  • [in] b: double b[3]

static WARN_RESULT_IGNORED int eig_3x3(double *restrict a, double *restrict b, double *restrict eig)

Computation of the eigenvalues of a symmetric 3x3 real matrix.

Return

0 all the time

Parameters
  • a: symmetric column-major matrix (not modified)

  • b: a 3x3 work matrix

  • [inout] eig: eigenvalie in decreasing order

static int equal3(double *restrict a, double *restrict b)

check equality : a[3] == b[3]

Return

1 if true, 0 if false

Parameters
  • [in] a: double a[3]

  • [in] b: double b[3]

static int equal3x3(double *restrict a, double *restrict b)

check equality : a[9] == b[9]

Return

1 if true, 0 if false

Parameters
  • [in] a: double a[9]

  • [in] b: double b[9]

static void extract3x3(int n, int i0, int j0, double *restrict a, double *restrict b)

extract3x3 : copy a sub 3x3 matrix of *a into *b

static double hypot2(double *a)

norm : || a || may underflow & overflow

Return

the norm

Parameters
  • [in] a: a[2]

static double hypot3(double *a)

norm : || a || may underflow & overflow

Return

the norm

Parameters
  • [in] a: a[3]

static double hypot5(double *a)
static double hypot9(double *a)
static void insert3x3(int n, int i0, int j0, double *restrict a, double *restrict b)

insert3x3 : insert a 3x3 matrix *b into *a

static void mm3x3(double *restrict a, double *restrict b, double *restrict c)

matrix matrix multiplication : c = a * b

Parameters
  • [in] a: a[9]

  • [in] b: b[9]

  • [out] c: c[9]

static void mmm3x3(double *restrict a, double *restrict b, double *restrict c)

sub a matrix matrix multiplication : c -= a*b

Parameters
  • [in] a: a[9]

  • [in] b: b[9]

  • [out] c: c[9]

static void mmp3x3(double *restrict a, double *restrict b, double *restrict c)

add a matrix matrix multiplication : c += a*b

Parameters
  • [in] a: a[9]

  • [in] b: b[9]

  • [out] c: c[9]

static void mtv3x3(double *restrict a, double *restrict v, double *restrict r)

transpose(matrix) vector multiplication

Parameters
  • [in] a: 3 by 3 matrix in col-major

  • [in] v: 3 dimensional vector

  • [out] r: \(r = a^T*v\)

static void mtvm3x3(double *restrict a, double *restrict v, double *restrict r)

transpose(matrix) vector multiplication

Parameters
  • [in] a: 3 by 3 matrix in col-major

  • [in] v: 3 dimensional vector

  • [out] r: \(r = a^T*v\)

static void mv3x3(double *restrict a, double *restrict v, double *restrict r)

matrix vector multiplication

Parameters
  • [in] a: 3 by 3 matrix in col-major

  • [in] v: 3 dimensional vector

  • [out] r: \(r = a*v\)

static void mvm3x3(double *restrict a, double *restrict v, double *restrict r)

minux the result a matrix vector multiplication

Parameters
  • [in] a: matrix

  • [in] v: vector

  • [out] r: the result of r -= av

static void mvp3x3(const double *restrict a, const double *restrict v, double *restrict r)

add a matrix vector multiplication

Parameters
  • [in] a: a[9]

  • [in] v: v[3]

  • [out] r: r[3] the result of r += av

static void mvp5x5(const double *restrict a, const double *restrict v, double *restrict r)
static void mvp_alpha3x3(double alpha, const double *restrict a, const double *restrict v, double *restrict r)

add a matrix vector multiplication scaled by alpha

Parameters
  • [in] alpha: scalar coeff

  • [in] a: a[9]

  • [in] v: v[3]

  • [out] r: r[3] the result of r += av

static WARN_RESULT_IGNORED int orthoBaseFromVector(double * Ax, double * Ay, double * Az, double * A1x, double * A1y, double * A1z, double * A2x, double * A2y, double * A2z)

orthoBaseFromVector : From a vector A, build a matrix (A,A1,A2) such that it is an orthonormal.

Return

0 if success, 1 if there is a problem

Parameters
  • [inout] Ax: first component of the vector A

  • [inout] Ay: second component of the vector A

  • [inout] Az: third component of the vector A

  • [out] A1x: first component of the vector A

  • [out] A1y: second component of the vector A

  • [out] A1z: third component of the vector A

  • [out] A2x: first component of the vector A

  • [out] A2y: second component of the vector A

  • [out] A2z: third component of the vector A

void print3(double *v)

print a vector

Parameters
  • [in] v: the vector

void print3x3(double *mat)

print a matrix

Parameters
  • mat: the matrix

static void scal3(double scal, double *v)

scalar multiplication of a vector3

Parameters
  • [in] scal: double scalar

  • [inout] v: v[3]

static void scal3x3(double scal, double m[9])

scalar multiplication of a matrix3x3

Parameters
  • [in] scal: double scalar

  • [inout] m: m[9]

static WARN_RESULT_IGNORED int solv3x3(double *restrict a, double *restrict x, double *restrict b)

system resolution : x <- sol(Ax = b)

Return

0 if success, 1 if failed

Parameters
  • [in] a: double a[9]

  • [out] x: double x[3]

  • [in] b: double b[3]

static WARN_RESULT_IGNORED int solve_3x3_gepp(const double *restrict a, double *restrict b)

solve Ax = b by partial pivoting Gaussian elimination.

This function is 10 to 20 times faster than calling LAPACK (tested with netlib).

Return

0 if ok, otherwise the column where no pivot could be selected

Parameters
  • a: column-major matrix (not modified)

  • [inout] b: on input, the right-hand side; on output the solution x

static void solve_nxn_gepp(int n, double *a, double *b, double *x)
static void sub3(double a[3], double b[3])

sub a vector[3]

Parameters
  • [in] a: a[3]

  • [inout] b: b[3]

static void sub3x3(double a[9], double b[9])

sub a 3x3 matrix or a vector[9]

Parameters
  • [in] a: a[9]

  • [inout] b: b[9]

static void swap_row(double *a, double *b, int r1, int r2, int n)