Class Matrix4

    • Field Summary

      Fields 
      Modifier and Type Field Description
      double m00
      The first matrix element in the first row.
      double m01
      The second matrix element in the first row.
      double m02
      The third matrix element in the first row.
      double m03
      The forth matrix element in the first row.
      double m10
      The first matrix element in the second row.
      double m11
      The second matrix element in the second row.
      double m12
      The third matrix element in the second row.
      double m13
      The forth matrix element in the second row.
      double m20
      The first matrix element in the third row.
      double m21
      The second matrix element in the third row.
      double m22
      The third matrix element in the third row.
      double m23
      The forth matrix element in the third row.
      double m30
      The first matrix element in the forth row.
      double m31
      The second matrix element in the forth row.
      double m32
      The third matrix element in the forth row.
      double m33
      The forth matrix element in the forth row.
      static int SIZE
      The matrix size, which is 4.
    • Constructor Summary

      Constructors 
      Constructor Description
      Matrix4()
      Creates a new identity matrix.
      Matrix4​(double[] elements)
      Creates a new matrix initialized to the specified values.
      Matrix4​(double m00, double m01, double m02, double m03, double m10, double m11, double m12, double m13, double m20, double m21, double m22, double m23, double m30, double m31, double m32, double m33)
      Creates a new matrix initialized to the specified values.
    • Field Detail

      • m00

        public double m00
        The first matrix element in the first row.
      • m01

        public double m01
        The second matrix element in the first row.
      • m02

        public double m02
        The third matrix element in the first row.
      • m03

        public double m03
        The forth matrix element in the first row.
      • m10

        public double m10
        The first matrix element in the second row.
      • m11

        public double m11
        The second matrix element in the second row.
      • m12

        public double m12
        The third matrix element in the second row.
      • m13

        public double m13
        The forth matrix element in the second row.
      • m20

        public double m20
        The first matrix element in the third row.
      • m21

        public double m21
        The second matrix element in the third row.
      • m22

        public double m22
        The third matrix element in the third row.
      • m23

        public double m23
        The forth matrix element in the third row.
      • m30

        public double m30
        The first matrix element in the forth row.
      • m31

        public double m31
        The second matrix element in the forth row.
      • m32

        public double m32
        The third matrix element in the forth row.
      • m33

        public double m33
        The forth matrix element in the forth row.
    • Constructor Detail

      • Matrix4

        public Matrix4()
        Creates a new identity matrix.
      • Matrix4

        public Matrix4​(double m00,
                       double m01,
                       double m02,
                       double m03,
                       double m10,
                       double m11,
                       double m12,
                       double m13,
                       double m20,
                       double m21,
                       double m22,
                       double m23,
                       double m30,
                       double m31,
                       double m32,
                       double m33)
        Creates a new matrix initialized to the specified values.
        Parameters:
        m00 - the first matrix element in the first row.
        m01 - the second matrix element in the first row.
        m02 - the third matrix element in the first row.
        m03 - the forth matrix element in the first row.
        m10 - the first matrix element in the second row.
        m11 - the second matrix element in the second row.
        m12 - the third matrix element in the second row.
        m13 - the forth matrix element in the second row.
        m20 - the first matrix element in the third row.
        m21 - the second matrix element in the third row.
        m22 - the third matrix element in the third row.
        m23 - the forth matrix element in the third row.
        m30 - the first matrix element in the forth row.
        m31 - the second matrix element in the forth row.
        m32 - the third matrix element in the forth row.
        m33 - the forth matrix element in the forth row.
    • Method Detail

      • castOrCopy

        public static Matrix4 castOrCopy​(Matrix matrix)
                                  throws MismatchedMatrixSizeException
        Casts or copies the given matrix to a Matrix4 implementation. If the given matrix is already an instance of Matrix4, then it is returned unchanged. Otherwise this method verifies the matrix size, then copies all elements in a new Matrix4 object.
        Parameters:
        matrix - the matrix to cast or copy, or null.
        Returns:
        the matrix argument if it can be safely casted (including null argument), or a copy of the given matrix otherwise.
        Throws:
        Mismatched­Matrix­Size­Exception - if the size of the given matrix is not 4×4.
      • getNumRow

        public final int getNumRow()
        Returns the number of rows in this matrix, which is always 4 in this implementation.
        Returns:
        always 4.
      • getNumCol

        public final int getNumCol()
        Returns the number of columns in this matrix, which is always 4 in this implementation.
        Returns:
        always 4.
      • getElement

        public final double getElement​(int row,
                                       int column)
        Retrieves the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance of Matrix4, then the m00m33 fields can be read directly for efficiency.
        Specified by:
        get­Element in interface Matrix
        Specified by:
        get­Element in class Matrix­SIS
        Parameters:
        row - the row index, from 0 inclusive to 4 exclusive.
        column - the column index, from 0 inclusive to 4 exclusive.
        Returns:
        the current value at the given row and column.
      • setElement

        public final void setElement​(int row,
                                     int column,
                                     double value)
        Modifies the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance of Matrix4, then the m00m33 fields can be set directly for efficiency.
        Parameters:
        row - the row index, from 0 inclusive to 4 exclusive.
        column - the column index, from 0 inclusive to 4 exclusive.
        value - the new value to set at the given row and column.
      • getElements

        public final double[] getElements()
        Returns all matrix elements in a flat, row-major (column indices vary fastest) array. The array length is 16.
        Overrides:
        get­Elements in class Matrix­SIS
        Returns:
        a copy of all current matrix elements in a row-major array.
      • setElements

        public final void setElements​(double[] elements)
        Sets all matrix elements from a flat, row-major (column indices vary fastest) array. The array length shall be 16.
        Specified by:
        set­Elements in class Matrix­SIS
        Parameters:
        elements - The new matrix elements in a row-major array.
        See Also:
        Matrices​.create(int, int, double[])
      • transpose

        public void transpose()
        Sets the value of this matrix to its transpose.
        Specified by:
        transpose in class Matrix­SIS