Package util
Class Matrix3D
java.lang.Object
util.Matrix3D
This class is based on the class Matrix3f from https://github.com/jMonkeyEngine/jmonkeyengine/blob/master/jme3-core/src/main/java/com/jme3/math/Matrix3f.java
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondouble[][]
asArray()
double
Returns the determinant.boolean
double
get
(int i, int j) Returns the element at the position i,j in the matrixdouble
getLengthSquaredFromColumn
(int col) Gets the sum of all number squared in a columndouble
getTrace()
Gets the trace (the sum of the diagonal) of the matrixint
hashCode()
static Matrix3D
identity()
Static method for clearly creating an identity matrixinvert()
Method to return the inverse of a matrixvoid
Makes an identity matrix.void
mult
(double scalar) Method to mutliply all values of the current matrix with a scalarvoid
scalarMultiplyColumn
(int col, double scalar) Sets the element at the position i,j in the matrixvoid
set
(int i, int j, double num) Sets the element at the position i,j in the matrixCopies the matrix argument.toString()
Helper function to print the 3x3 matrix to the consolezero()
Method to return a matrix with only zeros
-
Constructor Details
-
Matrix3D
public Matrix3D()Instantiates an identity matrix (diagonals = 1, other elements = 0). -
Matrix3D
public Matrix3D(double[] flattenedMatrix) Instantiates a matrix with specified elements.- Parameters:
flattenedMatrix
- the 3x3 Matrix as a 1d array. Must have 9 Elements.
-
Matrix3D
public Matrix3D(double[][] matrix) -
Matrix3D
Instantiates a copy of the matrix argument. If the argument is null, an identity matrix is produced.- Parameters:
mat
- the matrix to copy (unaffected) or null for identity
-
-
Method Details
-
identity
Static method for clearly creating an identity matrix- Returns:
- identity matrix
-
asArray
public double[][] asArray() -
set
Copies the matrix argument. If the argument is null, the current instance is set to identity (diagonals = 1, other elements = 0).- Parameters:
matrix
- the matrix to copy (unaffected) or null for identity- Returns:
- the (modified) current instance (for chaining)
-
makeIdentityMatrix
public void makeIdentityMatrix()Makes an identity matrix. (The diagonals are 1, the others are 0) -
zero
Method to return a matrix with only zeros- Returns:
- the matrix
-
get
public double get(int i, int j) Returns the element at the position i,j in the matrix- Parameters:
i
- the row indexj
- the column index- Returns:
- the value of the element at (i, j)
- Throws:
IllegalArgumentException
- if either index isn't 0, 1, or 2
-
set
public void set(int i, int j, double num) Sets the element at the position i,j in the matrix- Parameters:
i
- the row indexj
- the column index- Throws:
IllegalArgumentException
- if either index isn't 0, 1, or 2
-
scalarMultiplyColumn
public void scalarMultiplyColumn(int col, double scalar) Sets the element at the position i,j in the matrix- Parameters:
col
- the column to be multipliedscalar
- the scalar with which the column is multiplied
-
getLengthSquaredFromColumn
public double getLengthSquaredFromColumn(int col) Gets the sum of all number squared in a column- Parameters:
col
- the column over which the sum is computed- Returns:
- the squared sum of the column
-
getTrace
public double getTrace()Gets the trace (the sum of the diagonal) of the matrix- Returns:
- the trace (the sum of the diagonal) of the matrix
-
mult
-
mult
public void mult(double scalar) Method to mutliply all values of the current matrix with a scalar- Parameters:
scalar
- the number with which all values should be multiplied
-
toString
Helper function to print the 3x3 matrix to the console -
determinant
public double determinant()Returns the determinant. The matrix is unaffected.- Returns:
- the determinant
-
invert
Method to return the inverse of a matrix- Returns:
- the invert matrix
-
equals
-
hashCode
public int hashCode()
-