    Next: 2D Vector Algebra Functions Up: 2D and 3D vector Previous: 3D Vector Geometry   Contents

## 3D Matrix Algebra Functions

Note: this is not to be confused with the general matrix algebra package.

3D Matrices are structures containing a 3 by 3 float array (try not to use this). Functions usually pass matrices by value and return matrices. Again the convenience is worth the overhead.

```void *mat3_alloc()
```
Returns pointer to a newly allocated zero matrix.

```void *mat3_make(Mat3 m)
```
Returns pointer to a newly allocated copy of m.

```void mat3_free(Mat3 *m)
```
Frees an allocated matrix (for completeness, just calls rfree).

```Mat3    mat3(double mxx, double mxy, double mxz,
double myx, double myy, double myz,
double mzx, double mzy, double mzz)
```
Returns matrix with given components (arguments in row order).

```Mat3 mat3_unit()
```
Returns unit matrix.

```Mat3 mat3_zero()
```
Returns zero matrix.

```Macro mat3_xx()

Macro mat3_xy()

Macro mat3_zz()
```
Macros to return components of matrix (can be used on left and right hand sides of assignment statements).

```double mat3_get_xx()

double mat3_get_xy()

...

double mat3_get_zz()
```
Return components of matrix (function versions of above macros).

```void    mat3_comps(Mat3 m, float *mxx, float *mxy, float *mxz,
float *myx, float *myy, float *myz,
float *mzx, float *mzy, float *mzz)
```
Sets *mxx etc. to components of matrix m.

```Vec3 mat3_rowx(Mat3 m)

Vec3 mat3_rowy(Mat3 m)

Vec3 mat3_rowz(Mat3 m)
```
Return rows of matrix as Vec3's.

```Vec3 mat3_colx(Mat3 m)

Vec3 mat3_coly(Mat3 m)

Vec3 mat3_colz(Mat3 m)
```
Return columns of matrix as Vec3's.

```Mat3 mat3_of_cols(Vec3 cx, Vec3 cy, Vec3 cz)
```
Returns matrix with given column vectors.

```Mat3 mat3_of_rows(Vec3 rx, Vec3 ry, Vec3 rz)
```
Returns matrix with given row vectors.

```Mat3 mat3_sum(Mat3 m, Mat3 n)
```
Returns sum m+n of two matrices.

```Mat3 mat3_diff(Mat3 m, Mat3 n)
```
Returns difference m-n of two matrices.

```Mat3 mat3_minus(Mat3 m)
```
Returns negative -m of matrix.

```Mat3 mat3_times(double k, Mat3 m)
```
Returns (matrix) product km of a scalar and a matrix.

```Mat3 mat3_prod(Mat3 m, Mat3 n)
```
Returns matrix product mn of two matrices.

```Mat3 mat3_inverse(Mat3 m)
```
Returns inverse of a matrix (algorithm is usually plenty good enough for 3 by 3's).

```Mat3 mat3_transpose(Mat3 m)
```
Returns transpose of a matrix.

```double mat3_trace(Mat3 m)
```
Returns trace (sum of diagonal elements).

```double mat3_det(Mat3 m)
```
Returns determinant of matrix.

```Bool mat3_posdef(Mat3 m)
```
```Returns true if symmetric matrix is positive definite.
```
```Vec3 mat3_vprod(Mat3 m, Vec3 v)
```

Returns (vector) product mv of matrix and vector.

```Vec3 mat3_transpose_vprod(Mat3 m, Vec3 v)
```
Returns (vector) product m'v of transpose of matrix and vector.

```double mat3_sprod(Vec3 v, Mat3 m, Vec3 w)
```
Returns (scalar) contraction v'mw of matrix with two vectors.

```Mat3    mat3_tensor(Vec3 v, Vec3 w)
```
Returns (matrix) tensor product mij = vi*vj of two vectors.

```Mat3    mat3_read(FILE *fp)
```
Returns matrix read from ascii file.

```void    mat3_print(Mat3 fp, FILE *m)
```
Prints matrix to ascii file.

```void    mat3_pprint(FILE * fp, char *msg, Mat3 m)
```
Prints matrix (with introductory message) to ascii file.

```void    mat3_format(Mat3 m)
```
Prints matrix to Tina format output (stdio or main textsw).

```void    mat3_eigen(Mat3 m, double *eval, Vec3 * evec)
```
Returns the eigen values and eigen vectors of the matrix.    Next: 2D Vector Algebra Functions Up: 2D and 3D vector Previous: 3D Vector Geometry   Contents
root 2019-03-24