## Class Matrices

• ```public class Matrices
extends Object```
Utility class for linear algebra in 3-dimensional space. The array arguments to the methods here are either 3-element arrays representing 3-d vectors
```    ( v[0], v[1], v[2] )
```
or 9-element arrays representing 3-d matrices:
```    ( m[0], m[1], m[2],
m[3], m[4], m[5],
m[6], m[7], m[8] )
```
Since:
25 Nov 2005
Author:
Mark Taylor
• ### Constructor Summary

Constructors
Constructor and Description
`Matrices()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static double[]` `adj(double[] m)`
Calculates the adjoint of a matrix.
`static double[]` ```cross(double[] a, double[] b)```
Calculates the vector (cross) product of two vectors.
`static double` `det(double[] m)`
Calculates the determinant of a matrix.
`static double` ```dot(double[] a, double[] b)```
Calclulates the scalar (dot) product of two vectors.
`static double[]` `fromPal(double[][] m)`
Converts a 3-d matrix from Pal-friendly form (3x3) to the form used elsewhere in this class (flat 9-element array).
`static double[]` `invert(double[] m)`
Inverts a matrix.
`static double[]` ```mmMult(double[] a, double[] b)```
Multiplies two matrices together.
`static double` `mod(double[] v)`
Calculates the modulus of a vector.
`static double[]` ```mult(double[] v, double c)```
Multiplies a vector by a constant.
`static double[]` ```mvMult(double[] m, double[] v)```
Multiplies a matrix by a vector.
`static double[]` `normalise(double[] v)`
Normalises a vector.
`static double[][]` `toPal(double[] m)`
Converts a 3-d matrix from the form used in this class (flat 9-element array) to Pal-friendly form (3x3).
`static String` `toString(double[] a)`
Returns a string giving the contents of an arbitrary length vector.
`static double[]` `transpose(double[] a)`
Returns the transpose of a 3x3 matrix.
`static double[]` `unit(int iaxis)`
Returns a unit vector along an indicated axis.
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### Matrices

`public Matrices()`
• ### Method Detail

`public static double[] adj(double[] m)`
Calculates the adjoint of a matrix.
Parameters:
`m` - input matrix as 9-element array
Returns:
• #### det

`public static double det(double[] m)`
Calculates the determinant of a matrix.
Parameters:
`m` - input matrix as 9-element array
Returns:
det(m)
• #### invert

`public static double[] invert(double[] m)`
Inverts a matrix.
Parameters:
`m` - input matrix as 9-element array
Returns:
m-1 as 9-element array
• #### dot

```public static double dot(double[] a,
double[] b)```
Calclulates the scalar (dot) product of two vectors.
Parameters:
`a` - vector 1
`b` - vector 2
Returns:
a.b
• #### cross

```public static double[] cross(double[] a,
double[] b)```
Calculates the vector (cross) product of two vectors.
Parameters:
`a` - vector 1
`b` - vector 2
Returns:
a x b
• #### transpose

`public static double[] transpose(double[] a)`
Returns the transpose of a 3x3 matrix.
Parameters:
`a` - input matrix
Returns:
transpose of a
• #### unit

`public static double[] unit(int iaxis)`
Returns a unit vector along an indicated axis.
Parameters:
`iaxis` - index of axis (0, 1 or 2)
Returns:
unit vector `iaxis`
• #### mod

`public static double mod(double[] v)`
Calculates the modulus of a vector.
Parameters:
`v` - input vector
Returns:
`|v|`
• #### normalise

`public static double[] normalise(double[] v)`
Normalises a vector.
Parameters:
`v` - input vector
Returns:
`|v|`
• #### mult

```public static double[] mult(double[] v,
double c)```
Multiplies a vector by a constant.
Parameters:
`v` - vector of arbitrary length
`c` - constant factor
Returns:
v * c
• #### mvMult

```public static double[] mvMult(double[] m,
double[] v)```
Multiplies a matrix by a vector.
Parameters:
`m` - input matrix as 9-element array
`v` - input vector as 3-element array
Returns:
m * v
• #### mmMult

```public static double[] mmMult(double[] a,
double[] b)```
Multiplies two matrices together.
Parameters:
`a` - input matrix 1 as 9-element array
`b` - input matrix 2 as 9-element array
Returns:
a * b as 9-element array
• #### toString

`public static String toString(double[] a)`
Returns a string giving the contents of an arbitrary length vector.
Parameters:
`a` - array
Returns:
stringified `a`
• #### fromPal

`public static double[] fromPal(double[][] m)`
Converts a 3-d matrix from Pal-friendly form (3x3) to the form used elsewhere in this class (flat 9-element array).
Parameters:
`m` - flat matrix
Returns:
pal-friendly matrix
• #### toPal

`public static double[][] toPal(double[] m)`
Converts a 3-d matrix from the form used in this class (flat 9-element array) to Pal-friendly form (3x3).
Parameters:
`m` - flat matrix
Returns:
pal-friendly matrix