Package util

Class Matrix3D

java.lang.Object
util.Matrix3D

public class Matrix3D extends Object
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

    Constructors
    Constructor
    Description
    Instantiates an identity matrix (diagonals = 1, other elements = 0).
    Matrix3D(double[] flattenedMatrix)
    Instantiates a matrix with specified elements.
    Matrix3D(double[][] matrix)
     
    Instantiates a copy of the matrix argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    double[][]
     
    double
    Returns the determinant.
    boolean
     
    double
    get(int i, int j)
    Returns the element at the position i,j in the matrix
    double
    Gets the sum of all number squared in a column
    double
    Gets the trace (the sum of the diagonal) of the matrix
    int
     
    static Matrix3D
    Static method for clearly creating an identity matrix
    Method to return the inverse of a matrix
    void
    Makes an identity matrix.
    void
    mult(double scalar)
    Method to mutliply all values of the current matrix with a scalar
     
    void
    scalarMultiplyColumn(int col, double scalar)
    Sets the element at the position i,j in the matrix
    void
    set(int i, int j, double num)
    Sets the element at the position i,j in the matrix
    set(Matrix3D matrix)
    Copies the matrix argument.
    Helper function to print the 3x3 matrix to the console
    Method to return a matrix with only zeros

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • 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

      public Matrix3D(Matrix3D mat)
      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

      public static Matrix3D identity()
      Static method for clearly creating an identity matrix
      Returns:
      identity matrix
    • asArray

      public double[][] asArray()
    • set

      public Matrix3D set(Matrix3D matrix)
      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

      public Matrix3D 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 index
      j - 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 index
      j - 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 multiplied
      scalar - 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

      public Vector3D mult(Vector3D vec)
    • 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

      public String toString()
      Helper function to print the 3x3 matrix to the console
      Overrides:
      toString in class Object
    • determinant

      public double determinant()
      Returns the determinant. The matrix is unaffected.
      Returns:
      the determinant
    • invert

      public Matrix3D invert()
      Method to return the inverse of a matrix
      Returns:
      the invert matrix
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object