de.jreality.math

## Class Matrix

• All Implemented Interfaces:
Serializable
Direct Known Subclasses:
FactoredMatrix

```public class Matrix
extends Object
implements Serializable```
A simple wrapper class for 4x4 real matrices. The matrix is represented as a linear array of 16 values (double[16] in order to avoid problems with Java's multi-dimensional arrays. The elements are listed in row/column order and act on column vectors sitting to the right of the matrix.

This class is not supposed to be a replacement for a full-fledged mathematical package. It provides a convenient wrapper for double arrays that offers some basic functionality for multiplying and inverting matrices and such, but if you want to do more involved stuff, you probably want to use a dedicated math library.

Author:
weissman
`Rn`, `P3`, `Pn`, Serialized Form
• ### Field Summary

Fields
Modifier and Type Field and Description
`static double` `TOLERANCE`
• ### Constructor Summary

Constructors
Constructor and Description
`Matrix()`
`Matrix(double[] m)`
plain wrapper for the array m; does NOT make a copy of m!
`Matrix(DoubleArray data)`
this constructor copies the content of the given DoubleArray.
```Matrix(double x00, double x01, double x02, double x03, double x10, double x11, double x12, double x13, double x20, double x21, double x22, double x23, double x30, double x31, double x32, double x33)```
TODO
`Matrix(Matrix T)`
copy constructor
`Matrix(Transformation data)`
this constructor copies the content of the given Transformation.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`void` `add(Matrix T)`
Let M be the current Matrix.
`void` `assignFrom(double[] initValue)`
copies initValue
`void` `assignFrom(DoubleArray data)`
copies initValue
`void` ```assignFrom(double x00, double x01, double x02, double x03, double x10, double x11, double x12, double x13, double x20, double x21, double x22, double x23, double x30, double x31, double x32, double x33)```
TODO: assign single values!
`void` `assignFrom(Matrix initValue)`
copies initValue
`void` `assignFrom(Transformation trafo)`
copies initValue
`void` `assignIdentity()`
`void` `assignTo(double[] array)`
`void` `assignTo(Matrix m)`
`void` `assignTo(SceneGraphComponent comp)`
Set the matrix of the transformation of comp to be this instance.
`void` `assignTo(Transformation trafo)`
`static Matrix` ```conjugate(Matrix A, Matrix B)```
`void` `conjugateBy(Matrix T)`
Let M be the current Matrix.
`boolean` `containsNanOrInfinite()`
`boolean` `equals(Matrix T)`
`double[]` `getArray()`
`double[]` `getColumn(int i)`
`double` `getDeterminant()`
`double` ```getEntry(int row, int column)```
`Matrix` `getInverse()`
`double[]` `getRow(int i)`
`double` `getTrace()`
`Matrix` `getTranspose()`
`void` `invert()`
`void` `multiplyOnLeft(double[] T)`
Let M be the current matrix.
`void` `multiplyOnLeft(Matrix T)`
Let M be the current matrix.
`void` `multiplyOnRight(double[] T)`
Let M be the current matrix.
`void` `multiplyOnRight(Matrix T)`
Let M be the current matrix.
`double[]` `multiplyVector(double[] v)`
Form the matrix-vector product M.v (v is column vector on the right).
`static Matrix` ```power(Matrix m, int n)```
`void` ```setColumn(int i, double[] v)```
assigns the values of the ith column with the values from v.
`void` ```setEntry(int row, int column, double value)```
`void` ```setRow(int i, double[] v)```
`void` `subtract(Matrix T)`
Let M be the current Matrix.
`static Matrix` ```sum(Matrix A, Matrix B)```
`void` `times(double f)`
Let M be the current Matrix.
`static Matrix` ```times(Matrix A, Matrix B)```
`String` `toString()`
`void` `transformVector(double[] v)`
Form the matrix-vector product M.v (v is column vector on the right) and assign it to v.
`void` `transpose()`
`double[]` `writeToArray(double[] aMatrix)`
Copy the current matrix into aMatrix and return it.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### TOLERANCE

`public static final double TOLERANCE`
Constant Field Values
• ### Constructor Detail

• #### Matrix

`public Matrix()`
• #### Matrix

`public Matrix(Matrix T)`
copy constructor
Parameters:
`T` -
• #### Matrix

`public Matrix(double[] m)`
plain wrapper for the array m; does NOT make a copy of m!
Parameters:
`m` - the double array to be wrapped by this Matrix
• #### Matrix

```public Matrix(double x00,
double x01,
double x02,
double x03,
double x10,
double x11,
double x12,
double x13,
double x20,
double x21,
double x22,
double x23,
double x30,
double x31,
double x32,
double x33)```
TODO
• #### Matrix

`public Matrix(DoubleArray data)`
this constructor copies the content of the given DoubleArray. Note: the given DoubleArray must have length == 16
Parameters:
`the` - DoubleArray to copy and wrap
• #### Matrix

`public Matrix(Transformation data)`
this constructor copies the content of the given Transformation.
Parameters:
`the` - Transformation to copy and wrap
• ### Method Detail

• #### times

```public static Matrix times(Matrix A,
Matrix B)```
Parameters:
`A` -
`B` -
Returns:
A*B
• #### sum

```public static Matrix sum(Matrix A,
Matrix B)```
Parameters:
`A` -
`B` -
Returns:
A+B
• #### conjugate

```public static Matrix conjugate(Matrix A,
Matrix B)```
Parameters:
`A` -
`B` -
Returns:
B * A * B^-1
• #### power

```public static Matrix power(Matrix m,
int n)```
• #### assignFrom

`public void assignFrom(double[] initValue)`
copies initValue
Parameters:
`initValue` -
• #### assignFrom

`public void assignFrom(Matrix initValue)`
copies initValue
Parameters:
`initValue` -
• #### assignFrom

`public void assignFrom(DoubleArray data)`
copies initValue
Parameters:
`initValue` -
• #### assignFrom

`public void assignFrom(Transformation trafo)`
copies initValue
Parameters:
`initValue` -
• #### assignFrom

```public void assignFrom(double x00,
double x01,
double x02,
double x03,
double x10,
double x11,
double x12,
double x13,
double x20,
double x21,
double x22,
double x23,
double x30,
double x31,
double x32,
double x33)```
TODO: assign single values!
• #### assignTo

`public void assignTo(double[] array)`
• #### assignTo

`public void assignTo(Matrix m)`
• #### assignTo

`public void assignTo(Transformation trafo)`
• #### assignTo

`public void assignTo(SceneGraphComponent comp)`
Set the matrix of the transformation of comp to be this instance. If comp has no Transformation, create one.
Parameters:
`comp` -
• #### assignIdentity

`public void assignIdentity()`
• #### getDeterminant

`public double getDeterminant()`
• #### getTrace

`public double getTrace()`
• #### getEntry

```public double getEntry(int row,
int column)```
• #### setEntry

```public void setEntry(int row,
int column,
double value)```
• #### getRow

`public double[] getRow(int i)`
• #### setRow

```public void setRow(int i,
double[] v)```
• #### getColumn

`public double[] getColumn(int i)`
• #### setColumn

```public void setColumn(int i,
double[] v)```
assigns the values of the ith column with the values from v. if v.length == 3, then the 4th entry of the column is set to 0.
Parameters:
`i` -
`v` -
• #### getArray

`public double[] getArray()`
Returns:
reference to the current matrix
• #### writeToArray

`public double[] writeToArray(double[] aMatrix)`
Copy the current matrix into aMatrix and return it.
Parameters:
`aMatrix` -
Returns:
the filled in matrix
• #### multiplyOnRight

`public void multiplyOnRight(double[] T)`
Let M be the current matrix. Then form the matrix product M*T and store it in M.
Parameters:
`aMatrix` -
• #### multiplyOnRight

`public void multiplyOnRight(Matrix T)`
Let M be the current matrix. Then form the matrix product M*T and store it in M.
Parameters:
`aMatrix` -
• #### multiplyOnLeft

`public void multiplyOnLeft(double[] T)`
Let M be the current matrix. Then form the matrix product T*M and store it in M.
Parameters:
`aMatrix` -
• #### multiplyOnLeft

`public void multiplyOnLeft(Matrix T)`
Let M be the current matrix. Then form the matrix product T*M and store it in M.
Parameters:
`aMatrix` -
• #### conjugateBy

`public void conjugateBy(Matrix T)`
Let M be the current Matrix. assigns T * M * T^-1
Parameters:
`T` -

`public void add(Matrix T)`
Let M be the current Matrix. assigns M + T
Parameters:
`T` - the matrix to add
• #### subtract

`public void subtract(Matrix T)`
Let M be the current Matrix. assigns M - T
Parameters:
`T` - the matrix to subtract
• #### times

`public void times(double f)`
Let M be the current Matrix. assigns f * M
Parameters:
`f` - the scalar to multiply M with
• #### getInverse

`public Matrix getInverse()`
• #### invert

`public void invert()`
• #### getTranspose

`public Matrix getTranspose()`
• #### transpose

`public void transpose()`
• #### multiplyVector

`public double[] multiplyVector(double[] v)`
Form the matrix-vector product M.v (v is column vector on the right).
Parameters:
`v` - the vector v
Returns:
M.v
• #### transformVector

`public void transformVector(double[] v)`
Form the matrix-vector product M.v (v is column vector on the right) and assign it to v.
Parameters:
`vector` - the vector to transform
• #### equals

`public boolean equals(Matrix T)`
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### containsNanOrInfinite

`public boolean containsNanOrInfinite()`