Class Matrix2f

  • All Implemented Interfaces:
    java.io.Serializable

    public class Matrix2f
    extends java.lang.Object
    implements java.io.Serializable
    Matrix operations are applied on the left. For example, given a matrix M and a vector V, matrix-times-vector is M*V. That is, V is treated as a column vector. Some graphics APIs use V*M where V is treated as a row vector. In this context the "M" matrix is really a transpose of the M as represented in Wild Magic. Similarly, to apply two matrix operations M0 and M1, in that order, you compute M1*M0 so that the transform of a vector is (M1*M0)*V = M1*(M0*V). Some graphics APIs use M0*M1, but again these matrices are the transpose of those as represented in Wild Magic. You must therefore be careful about how you interface the transformation code with graphics APIS. Rotation matrices are of the form R = cos(t) -sin(t) sin(t) cos(t) where t > 0 indicates a counterclockwise rotation in the xy-plane.
    See Also:
    Serialized Form
    • Field Detail

      • ZERO

        public static final Matrix2f ZERO
        Zero matrix:
      • IDENTITY

        public static final Matrix2f IDENTITY
        Identity matrix:
      • M00

        public float M00
        Matrix data:
      • M01

        public float M01
        Matrix data:
      • M10

        public float M10
      • M11

        public float M11
    • Constructor Detail

      • Matrix2f

        public Matrix2f()
        Constructor, defaults to zero-matrix:
      • Matrix2f

        public Matrix2f​(boolean bZero)
        If bZero is true, create the zero matrix. Otherwise, create the identity matrix.
        Parameters:
        bZero - when true create zero matrix, when false create identity.
      • Matrix2f

        public Matrix2f​(float fAngle)
        Create rotation matrices (positive angle - counterclockwise). The angle must be in radians, not degrees.
        Parameters:
        fAngle - rotation angle in radians
      • Matrix2f

        public Matrix2f​(float fM00,
                        float fM11)
        create a diagonal matrix
        Parameters:
        fM00 - 0-diagonal value
        fM11 - 1-diagonal value
      • Matrix2f

        public Matrix2f​(float fM00,
                        float fM01,
                        float fM10,
                        float fM11)
        input Mrc is in row r, column c.
        Parameters:
        fM00 - matrix[0] entry
        fM01 - matrix[1] entry
        fM10 - matrix[2] entry
        fM11 - matrix[3] entry
      • Matrix2f

        public Matrix2f​(float[] afEntry,
                        boolean bRowMajor)
        Create a matrix from an array of numbers. The input array is interpreted based on the Boolean input as true: entry[0..3] = {m00,m01,m10,m11} [row major] false: entry[0..3] = {m00,m10,m01,m11} [column major]
        Parameters:
        afEntry - array of values to put in matrix
        bRowMajor - when true copy in row major order.
      • Matrix2f

        public Matrix2f​(Matrix2f rkM)
        copy constructor
        Parameters:
        rkM - matrix to copy.
      • Matrix2f

        public Matrix2f​(Vector2f rkU,
                        Vector2f rkV)
        create a tensor product U*V^T
        Parameters:
        rkU - U-Vector
        rkV - V-Vector
      • Matrix2f

        public Matrix2f​(Vector2f rkU,
                        Vector2f rkV,
                        boolean bColumns)
        Create matrices based on vector input. The Boolean is interpreted as true: vectors are columns of the matrix false: vectors are rows of the matrix
        Parameters:
        rkU - input vector1
        rkV - input vector2
        bColumns - when true vectors are columns of matrix.
      • Matrix2f

        public Matrix2f​(Vector2f[] akV,
                        boolean bColumns)
        Create matrices based on vector input. The Boolean is interpreted as true: vectors are columns of the matrix false: vectors are rows of the matrix
        Parameters:
        akV - input vector[2]
        bColumns - when true vectors are columns of matrix.
    • Method Detail

      • add

        public Matrix2f add​(float fM00,
                            float fM01,
                            float fM10,
                            float fM11)
        Add to this matrix.
        Parameters:
        fM00 -
        fM01 -
        fM10 -
        fM11 -
      • adjoint

        public Matrix2f adjoint()
        Compute the adjoint of this matrix: this = Adjoint(this)
      • copy

        public Matrix2f copy​(Matrix2f rkM)
        Set the values of this.
        Parameters:
        rkM - matrix to copy.
      • determinant

        public float determinant()
        Return the determinant of this matrix.
        Returns:
        the determinant of this matrix.
      • eigenDecomposition

        public void eigenDecomposition​(Matrix2f rkRot,
                                       Matrix2f rkDiag)
        Factor M = R*D*R^T. The columns of R are the eigenvectors. The diagonal entries of D are the corresponding eigenvalues.
        Parameters:
        rkRot -
        rkDiag -
      • fromAngle

        public Matrix2f fromAngle​(float fAngle)
        Create a rotation matrix from an angle in radians.
        Parameters:
        fAngle - rotation angle in radians
      • get

        public final float get​(int iIndex)
        Get member access
        Parameters:
        iIndex - matrix index
        Returns:
        matrix[iIndex]
      • get

        public final float get​(int iRow,
                               int iCol)
        Get member access
        Parameters:
        iRow - row-value
        iCol - column-value
        Returns:
        matrix[iRow*3 + iCol]
      • getColumn

        public void getColumn​(int iCol,
                              Vector2f kResult)
        Get member access
        Parameters:
        iCol - column to get
        kResult - column vector values
      • getColumnMajor

        public void getColumnMajor​(float[] afCMajor)
        Get member access. Copies matrix into input array in Column-Major order.
        Parameters:
        afCMajor - copy matrix into array.
      • getData

        public void getData​(float[] afData)
        Get member access. Copies matrix into input array.
        Parameters:
        afData - copy matrix into array.
      • inverse

        public Matrix2f inverse()
        Invert a 3x3 using cofactors. This is faster than using a generic Gaussian elimination because of the loop overhead of such a method. this = this -1
      • inverse

        public static Matrix2f inverse​(Matrix2f kM)
        Invert using cofactors. This is faster than using a generic Gaussian elimination because of the loop overhead of such a method.
        Parameters:
        kM - the matrix to invert. this = kM-1
      • makeDiagonal

        public Matrix2f makeDiagonal​(float fM00,
                                     float fM11)
        Create a diagonal matrix:
        Parameters:
        fM00 - matrix[0] entry
        fM11 - matrix[3] entry
      • identity

        public Matrix2f identity()
        make this the identity matrix
      • makeTensorProduct

        public Matrix2f makeTensorProduct​(Vector2f rkU,
                                          Vector2f rkV)
        create a tensor product U*V^T
        Parameters:
        rkU - U-Vector
        rkV - V-Vector
      • makeZero

        public Matrix2f makeZero()
        make this the zero matrix
      • mult

        public Matrix2f mult​(Matrix2f kM)
        Multiply this matrix to the input matrix: this = this * kM.
        Parameters:
        kM - input matrix
      • mult

        public static Matrix2f mult​(Matrix2f kM1,
                                    Matrix2f kM2)
        Multiply this matrix to the input matrix: this = kM1 * kM2.
        Parameters:
        kM1 - first input matrix
        kM2 - second input matrix
      • mult

        public void mult​(Vector2f kV,
                         Vector2f kResult)
        Matrix times vector: Result = this * v
        Parameters:
        kV - vector
        kResult - = this * v
      • mult

        public Vector2f mult​(Vector2f kV)
        Matrix times vector: Result = this * v
        Parameters:
        kV - vector
        kResult - = this * v
      • multLeft

        public Matrix2f multLeft​(Matrix2f kM)
        Multiply this matrix to the input matrix: this = kM * this.
        Parameters:
        kM - input matrix
      • multLeft

        public void multLeft​(Vector2f kV,
                             Vector2f kResult)
        matrix times vector: kResult = v^T * this
        Parameters:
        kV - vector
        kResult - = v^T * this
      • multLeft

        public Vector2f multLeft​(Vector2f kV)
        matrix times vector: kResult = v^T * this
        Parameters:
        kV - vector
        kResult - = v^T * this
      • multRight

        public void multRight​(Vector2f kV,
                              Vector2f kResult)
        Matrix times vector: Result = this * v
        Parameters:
        kV - vector
        kResult - = this * v
      • multRight

        public Vector2f multRight​(Vector2f kV)
        Matrix times vector: Result = this * v
        Parameters:
        kV - vector
        kResult - = this * v
      • orthonormalize

        public Matrix2f orthonormalize()
        The matrix must be a rotation for these functions to be valid. The last function uses Gram-Schmidt orthonormalization applied to the columns of the rotation matrix. The angle must be in radians, not degrees. Algorithm uses Gram-Schmidt orthogonalization. If 'this' matrix is M = [m0|m1], then orthonormal output matrix is Q = [q0|q1], q0 = m0/|m0| q1 = (m1-(q0*m1)q0)/|m1-(q0*m1)q0| where |V| indicates length of vector V and A*B indicates dot product of vectors A and B.
      • qForm

        public float qForm​(Vector2f rkU,
                           Vector2f rkV)
        Calculate and return u^T*M*v
        Parameters:
        rkU - u
        rkV - v
        Returns:
        u^T*M*v
      • scale

        public Matrix2f scale​(float fScalar)
        Multiply this matrix by the scalar input: this = this * fScalar.
        Parameters:
        fScalar - scalar value
      • set

        public Matrix2f set​(float fM00,
                            float fM01,
                            float fM10,
                            float fM11)
        input Mrc is in row r, column c.
        Parameters:
        fM00 - matrix[0] entry
        fM01 - matrix[1] entry
        fM10 - matrix[2] entry
        fM11 - matrix[3] entry
      • set

        public Matrix2f set​(int iIndex,
                            float fValue)
        Parameters:
        iIndex - matrix index
      • set

        public Matrix2f set​(int iRow,
                            int iCol,
                            float fValue)
        Set the values of this.
        Parameters:
        iRow - row-value
        iCol - column-value
        fValue - matrix[iIndex] new value
      • setColumn

        public Matrix2f setColumn​(int iCol,
                                  Vector2f kV)
        Set member access
        Parameters:
        iCol - column to set
        kV - new column vector values
      • timesTranspose

        public Matrix2f timesTranspose​(Matrix2f kM)
        Multiply this matrix by transpose of the input matrix: this = this * M^T
        Parameters:
        kM - matrix
      • toAngle

        public float toAngle()
        The matrix must be a rotation.
        Returns:
        rotation angle
      • toString

        public java.lang.String toString()
        Returns a string representation of the matrix values.
        Overrides:
        toString in class java.lang.Object
        Returns:
        string representation of the matrix values.
      • transpose

        public Matrix2f transpose()
        Transpose this matrix: this = this^T
      • transposeTimes

        public Matrix2f transposeTimes​(Matrix2f kM)
        Transpose this matrix and multiply by input: this = this^T * M
        Parameters:
        kM - input matrix