Class Matrix3f

  • All Implemented Interfaces:
    java.io.Serializable

    public class Matrix3f
    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. The (x,y,z) coordinate system is assumed to be right-handed. Coordinate axis rotation matrices are of the form RX = 1 0 0 0 cos(t) -sin(t) 0 sin(t) cos(t) where t > 0 indicates a counterclockwise rotation in the yz-plane RY = cos(t) 0 sin(t) 0 1 0 -sin(t) 0 cos(t) where t > 0 indicates a counterclockwise rotation in the zx-plane RZ = cos(t) -sin(t) 0 sin(t) cos(t) 0 0 0 1 where t > 0 indicates a counterclockwise rotation in the xy-plane.
    See Also:
    Serialized Form
    • Field Detail

      • ZERO

        public static final Matrix3f ZERO
        Zero matrix:
      • IDENTITY

        public static final Matrix3f IDENTITY
        Identity matrix:
      • M00

        public float M00
        Matrix data:
      • M01

        public float M01
        Matrix data:
      • M02

        public float M02
        Matrix data:
      • M10

        public float M10
      • M11

        public float M11
      • M12

        public float M12
      • M20

        public float M20
      • M21

        public float M21
      • M22

        public float M22
    • Constructor Detail

      • Matrix3f

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

        public Matrix3f​(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.
      • Matrix3f

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

        public Matrix3f​(float fM00,
                        float fM01,
                        float fM02,
                        float fM10,
                        float fM11,
                        float fM12,
                        float fM20,
                        float fM21,
                        float fM22)
        input Mrc is in row r, column c.
        Parameters:
        fM00 - matrix[0] entry
        fM01 - matrix[1] entry
        fM02 - matrix[2] entry
        fM10 - matrix[3] entry
        fM11 - matrix[4] entry
        fM12 - matrix[5] entry
        fM20 - matrix[6] entry
        fM21 - matrix[7] entry
        fM22 - matrix[8] entry
      • Matrix3f

        public Matrix3f​(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..8]={m00,m01,m02,m10,m11,m12,m20,m21,m22} [row major] false: entry[0..8]={m00,m10,m20,m01,m11,m21,m02,m12,m22} [col major]
        Parameters:
        afEntry - array of values to put in matrix
        bRowMajor - when true copy in row major order.
      • Matrix3f

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

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

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

        public Matrix3f​(Vector3f rkU,
                        Vector3f rkV,
                        Vector3f rkW,
                        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
        rkW - input vector3
        bColumns - when true vectors are columns of matrix.
      • Matrix3f

        public Matrix3f​(Vector3f[] 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[3]
        bColumns - when true vectors are columns of matrix.
    • Method Detail

      • EigenDecomposition

        public static boolean EigenDecomposition​(Matrix3f rkRot,
                                                 Matrix3f rkDiag)
        Deprecated.
        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 -
      • eigenDecomposition

        public static boolean eigenDecomposition​(Matrix3f rkRot,
                                                 Matrix3f 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 -
      • qlAlgorithm

        private static boolean qlAlgorithm​(Matrix3f rkRot,
                                           float[] afDiag,
                                           float[] afSubd)
        This is an implementation of the symmetric QR algorithm from the book "Matrix Computations" by Gene H. Golub and Charles F. Van Loan, second edition. The algorithm is 8.2.3. The implementation has a slight variation to actually make it a QL algorithm, and it traps the case when either of the subdiagonal terms s0 or s1 is zero and reduces the 2-by-2 subblock directly.
        Parameters:
        rkRot -
        afDiag -
        afSubd -
      • tridiagonalize

        private static boolean tridiagonalize​(Matrix3f rkRot,
                                              float[] afDiag,
                                              float[] afSubd)
        Householder reduction T = Q^t M Q Input: mat, symmetric 3x3 matrix M Output:
        Parameters:
        rkRot - mat, orthogonal matrix Q (a reflection)
        afDiag - diag, diagonal entries of T
        afSubd - subd, subdiagonal entries of T (T is symmetric)
      • Add

        public final void Add​(float fM00,
                              float fM01,
                              float fM02,
                              float fM10,
                              float fM11,
                              float fM12,
                              float fM20,
                              float fM21,
                              float fM22)
        Deprecated.
        Add to this matrix.
        Parameters:
        fM00 -
        fM01 -
        fM02 -
        fM10 -
        fM11 -
        fM12 -
        fM20 -
        fM21 -
        fM22 -
      • add

        public final Matrix3f add​(float fM00,
                                  float fM01,
                                  float fM02,
                                  float fM10,
                                  float fM11,
                                  float fM12,
                                  float fM20,
                                  float fM21,
                                  float fM22)
      • Add

        public final void Add​(Matrix3f kMat)
        Deprecated.
        Add to this matrix.
        Parameters:
        kMat -
      • add

        public Matrix3f add​(Matrix3f kMat)
        this = this + kMat
        Parameters:
        kMat -
        Returns:
        this
      • Add

        public final void Add​(Matrix3f kMat1,
                              Matrix3f kMat2)
        Deprecated.
        Add to this matrix = kMat1 + kMat2.
        Parameters:
        kMat1 -
        kMat2 -
      • Adjoint

        public void Adjoint()
        Deprecated.
        Compute the adjoint of this matrix: this = Adjoint(this)
      • Copy

        public void Copy​(Matrix3f rkM)
        Deprecated.
        Set the values of this.
        Parameters:
        rkM - matrix to copy.
      • copy

        public Matrix3f copy​(Matrix3f rkM)
        Copy this = rkM
        Parameters:
        rkM -
        Returns:
        this
      • Determinant

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

        public float determinant()
      • DiagonalTimes

        public void DiagonalTimes​(Vector3f kDiag)
        Deprecated.
        Compute the diagonal vector times this matrix: this = D*M
        Parameters:
        kDiag - diagonal vector
      • FromAxisAngle

        public void FromAxisAngle​(Vector3f rkAxis,
                                  float fAngle)
        Deprecated.
        Create a rotation matrix from an axis and angle in radians.
        Parameters:
        rkAxis - rotation axis
        fAngle - rotation angle in radians
      • fromAxisAngle

        public Matrix3f fromAxisAngle​(Vector3f rkAxis,
                                      float fAngle)
      • Get

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

        public final float get​(int iIndex)
      • Get

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

        public final float get​(int iRow,
                               int iCol)
      • GetColumn

        public void GetColumn​(int iCol,
                              Vector3f kResult)
        Deprecated.
        Get member access
        Parameters:
        iCol - column to get
        kResult - column vector values
      • getColumn

        public void getColumn​(int iCol,
                              Vector3f kResult)
      • getColumn

        public Vector3f getColumn​(int iCol)
      • GetColumnMajor

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

        public void getColumnMajor​(float[] afCMajor)
      • GetData

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

        public void getData​(float[] afData)
      • Inverse

        public void Inverse()
        Deprecated.
        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 Matrix3f 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
        Returns:
        this
      • Inverse

        public void Inverse​(Matrix3f kM)
        Deprecated.
        Invert a 3x3 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 void MakeDiagonal​(float fM00,
                                 float fM11,
                                 float fM22)
        Deprecated.
        Create a diagonal matrix:
        Parameters:
        fM00 - matrix[0] entry
        fM11 - matrix[4] entry
        fM22 - matrix[8] entry
      • makeDiagonal

        public Matrix3f makeDiagonal​(float fM00,
                                     float fM11,
                                     float fM22)
      • MakeIdentity

        public void MakeIdentity()
        Deprecated.
        make this the identity matrix
      • MakeTensorProduct

        public void MakeTensorProduct​(Vector3f rkU,
                                      Vector3f rkV)
        Deprecated.
        create a tensor product U*V^T
        Parameters:
        rkU - U-Vector
        rkV - V-Vector
      • MakeZero

        public void MakeZero()
        Deprecated.
        make this the zero matrix
      • Mult

        public void Mult​(Matrix3f kM)
        Deprecated.
        Multiply this matrix to the input matrix: this = this * kM.
        Parameters:
        kM - input matrix
      • Mult

        public void Mult​(Matrix3f kM1,
                         Matrix3f kM2)
        Deprecated.
        Multiply this matrix to the input matrix: this = kM1 * kM2.
        Parameters:
        kM1 - first input matrix
        kM2 - second input matrix
      • Mult

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

        public void mult​(Vector3f kV,
                         Vector3f kResult)
        kResult = this * kV
        Parameters:
        kV -
        kResult -
      • MultLeft

        public void MultLeft​(Matrix3f kM)
        Deprecated.
        Multiply this matrix to the input matrix: this = kM * this.
        Parameters:
        kM - input matrix
      • multLeft

        public Matrix3f multLeft​(Matrix3f kM)
        this = kM * this
        Parameters:
        kM -
        Returns:
        this
      • MultLeft

        public void MultLeft​(Vector3f kV,
                             Vector3f kResult)
        Deprecated.
        matrix times vector: kResult = v^T * this
        Parameters:
        kV - vector
        kResult - = v^T * this
      • Orthonormalize

        public void Orthonormalize()
        Deprecated.
        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|m2], then orthonormal output matrix is Q = [q0|q1|q2], q0 = m0/|m0| q1 = (m1-(q0*m1)q0)/|m1-(q0*m1)q0| q2 = (m2-(q0*m2)q0-(q1*m2)q1)/|m2-(q0*m2)q0-(q1*m2)q1| where |V| indicates length of vector V and A*B indicates dot product of vectors A and B.
      • orthonormalize

        public Matrix3f 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|m2], then orthonormal output matrix is Q = [q0|q1|q2], q0 = m0/|m0| q1 = (m1-(q0*m1)q0)/|m1-(q0*m1)q0| q2 = (m2-(q0*m2)q0-(q1*m2)q1)/|m2-(q0*m2)q0-(q1*m2)q1| where |V| indicates length of vector V and A*B indicates dot product of vectors A and B.
        Returns:
        this
      • QForm

        public float QForm​(Vector3f rkU,
                           Vector3f rkV)
        Deprecated.
        Calculate and return u^T*M*v
        Parameters:
        rkU - u
        rkV - v
        Returns:
        u^T*M*v
      • Scale

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

        public Matrix3f scale​(float fScalar)
        this = this * fScalar
        Parameters:
        fScalar -
        Returns:
        this
      • Set

        public final void Set​(float fM00,
                              float fM01,
                              float fM02,
                              float fM10,
                              float fM11,
                              float fM12,
                              float fM20,
                              float fM21,
                              float fM22)
        Deprecated.
        input Mrc is in row r, column c.
        Parameters:
        fM00 - matrix[0] entry
        fM01 - matrix[1] entry
        fM02 - matrix[2] entry
        fM10 - matrix[3] entry
        fM11 - matrix[4] entry
        fM12 - matrix[5] entry
        fM20 - matrix[6] entry
        fM21 - matrix[7] entry
        fM22 - matrix[8] entry
      • set

        public Matrix3f set​(float fM00,
                            float fM01,
                            float fM02,
                            float fM10,
                            float fM11,
                            float fM12,
                            float fM20,
                            float fM21,
                            float fM22)
      • Set

        public void Set​(float[] afEntry,
                        boolean bRowMajor)
        Deprecated.
        Create a matrix from an array of numbers. The input array is interpreted based on the Boolean input as true: entry[0..8]={m00,m01,m02,m10,m11,m12,m20,m21,m22} [row major] false: entry[0..8]={m00,m10,m20,m01,m11,m21,m02,m12,m22} [col major]
        Parameters:
        afEntry - array of values to put in matrix
        bRowMajor - when true copy in row major order.
      • set

        public Matrix3f set​(float[] afEntry,
                            boolean bRowMajor)
      • Set

        public void Set​(int iIndex,
                        float fValue)
        Deprecated.
        Parameters:
        iIndex - matrix index
      • set

        public Matrix3f set​(int iIndex,
                            float fValue)
      • Set

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

        public final Matrix3f set​(int iRow,
                                  int iCol,
                                  float fValue)
      • SetColumn

        public void SetColumn​(int iCol,
                              Vector3f kV)
        Deprecated.
        Set member access
        Parameters:
        iCol - column to set
        kV - new column vector values
      • TimesDiagonal

        public void TimesDiagonal​(Vector3f kDiag)
        Deprecated.
        Compute this matrix times the diagonal vector: this = M*D
        Parameters:
        kDiag - diagonal vector
      • timesDiagonal

        public Matrix3f timesDiagonal​(Vector3f kDiag)
        Compute this matrix times the diagonal vector: this = M*D
        Parameters:
        kDiag - diagonal vector
        Returns:
        this
      • TimesTranspose

        public void TimesTranspose​(Matrix3f kM)
        Deprecated.
        Multiply this matrix by transpose of the input matrix: this = this * M^T
        Parameters:
        kM - matrix
      • ToAxisAngle

        public float ToAxisAngle​(Vector3f rkAxis)
        Deprecated.
        The matrix must be a rotation for these functions to be valid. Let (x,y,z) be the unit-length axis and let A be an angle of rotation. The rotation matrix is R = I + sin(A)*P + (1-cos(A))*P^2 where I is the identity and +- -+ P = | 0 -z +y | | +z 0 -x | | -y +x 0 | +- -+ If A > 0, R represents a counterclockwise rotation about the axis in the sense of looking from the tip of the axis vector towards the origin. Some algebra will show that cos(A) = (trace(R)-1)/2 and R - R^t = 2*sin(A)*P In the event that A = pi, R-R^t = 0 which prevents us from extracting the axis through P. Instead note that R = I+2*P^2 when A = pi, so P^2 = (R-I)/2. The diagonal entries of P^2 are x^2-1, y^2-1, and z^2-1. We can solve these for axis (x,y,z). Because the angle is pi, it does not matter which sign you choose on the square roots.
        Parameters:
        rkAxis - rotation axis
        Returns:
        rotation angle
      • toAxisAngle

        public float toAxisAngle​(Vector3f rkAxis)
      • 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 void Transpose()
        Deprecated.
        Transpose this matrix: this = this^T
      • transpose

        public Matrix3f transpose()
        Transpose this matrix: this = this^T
        Returns:
        this
      • TransposeTimes

        public void TransposeTimes​(Matrix3f kM)
        Deprecated.
        Transpose this matrix and multiply by input: this = this^T * M
        Parameters:
        kM - input matrix
      • equals

        public boolean equals​(java.lang.Object kObject)
        Overrides:
        equals in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)
      • test

        public static boolean test()
      • test

        public static boolean test​(int count)