Class Matrix4d

  • All Implemented Interfaces:
    java.io.Serializable

    public class Matrix4d
    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.
    See Also:
    Serialized Form
    • Field Detail

      • ZERO

        public static final Matrix4d ZERO
        Zero matrix:
      • IDENTITY

        public static final Matrix4d IDENTITY
        Identity matrix:
      • M00

        public double M00
        Matrix data:
      • M01

        public double M01
        Matrix data:
      • M02

        public double M02
        Matrix data:
      • M03

        public double M03
        Matrix data:
      • M10

        public double M10
      • M11

        public double M11
      • M12

        public double M12
      • M13

        public double M13
      • M20

        public double M20
      • M21

        public double M21
      • M22

        public double M22
      • M23

        public double M23
      • M30

        public double M30
      • M31

        public double M31
      • M32

        public double M32
      • M33

        public double M33
    • Constructor Detail

      • Matrix4d

        public Matrix4d()
        Create the zero matrix.
      • Matrix4d

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

        public Matrix4d​(double fM00,
                        double fM01,
                        double fM02,
                        double fM03,
                        double fM10,
                        double fM11,
                        double fM12,
                        double fM13,
                        double fM20,
                        double fM21,
                        double fM22,
                        double fM23,
                        double fM30,
                        double fM31,
                        double fM32,
                        double fM33)
        input Mrc is in row r, column c.
        Parameters:
        fM00 - matrix[0] entry
        fM01 - matrix[1] entry
        fM02 - matrix[2] entry
        fM03 - matrix[3] entry
        fM10 - matrix[4] entry
        fM11 - matrix[5] entry
        fM12 - matrix[6] entry
        fM13 - matrix[7] entry
        fM20 - matrix[8] entry
        fM21 - matrix[9] entry
        fM22 - matrix[10] entry
        fM23 - matrix[11] entry
        fM30 - matrix[12] entry
        fM31 - matrix[13] entry
        fM32 - matrix[14] entry
        fM33 - matrix[15] entry
      • Matrix4d

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

        public Matrix4d​(Matrix4d rkM)
        copy constructor
        Parameters:
        rkM - matrix to copy
    • Method Detail

      • Adjoint

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

        public Matrix4d adjoint()
        Compute the adjoint of this matrix, setting this: this = Adjoint(this).
      • Copy

        public void Copy​(Matrix4d rkM)
        Deprecated.
        copy, overwrite this.
        Parameters:
        rkM - matrix to copy
      • copy

        public Matrix4d copy​(Matrix4d rkM)
        copy, overwrite this.
        Parameters:
        rkM - matrix to copy
      • Determinant

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

        public double determinant()
        Return the determinant of this matrix.
        Returns:
        the determinant of this matrix.
      • equals

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

        public final double Get​(int iRow,
                                int iCol)
        Deprecated.
        Get member access
        Parameters:
        iRow - row to get
        iCol - column to get
        Returns:
        value at m_afEntry[iRow*4 + iCol];
      • get

        public final double get​(int iRow,
                                int iCol)
        Get member access
        Parameters:
        iRow - row to get
        iCol - column to get
        Returns:
        value at m_afEntry[iRow*4 + iCol];
      • GetColumnMajor

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

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

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

        public void getData​(double[] afData)
        Get member access. Copies matrix into input array.
        Parameters:
        afData - 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 void Inverse()
        Deprecated.
        Invert a 4x4 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 Matrix4d inverse()
        Invert a 4x4 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 void Inverse​(Matrix4d kM)
        Deprecated.
        Invert a 4x4 using cofactors. This is faster than using a generic Gaussian elimination because of the loop overhead of such a method. this = kM -1
      • inverse

        public static Matrix4d inverse​(Matrix4d kM)
        Invert a 4x4 using cofactors. This is faster than using a generic Gaussian elimination because of the loop overhead of such a method. this = kM -1
      • MakeIdentity

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

        public Matrix4d identity()
        make this the identity matrix
      • MakeObliqueProjection

        public void MakeObliqueProjection​(Vector3d rkNormal,
                                          Vector3d rkPoint,
                                          Vector3d rkDirection)
        Deprecated.
        projection matrices onto a specified plane The projection plane is Dot(N,X-P) = 0 where N is a 3-by-1 unit-length normal vector and P is a 3-by-1 point on the plane. The projection is oblique to the plane, in the direction of the 3-by-1 vector D. Necessarily Dot(N,D) is not zero for this projection to make sense. Given a 3-by-1 point U, compute the intersection of the line U+t*D with the plane to obtain t = -Dot(N,U-P)/Dot(N,D). Then projection(U) = P + [I - D*N^T/Dot(N,D)]*(U-P) A 4-by-4 homogeneous transformation representing the projection is +- -+ M = | D*N^T - Dot(N,D)*I -Dot(N,P)D | | 0^T -Dot(N,D) | +- -+ where M applies to [U^T 1]^T by M*[U^T 1]^T. The matrix is chosen so that M[3][3] > 0 whenever Dot(N,D)
        Parameters:
        rkNormal - normal vector
        rkPoint - point
        rkDirection - direction vector
        • MakePerspectiveProjection

          public void MakePerspectiveProjection​(Vector3d rkNormal,
                                                Vector3d rkPoint,
                                                Vector3d rkEye)
          Deprecated.
          +- -+ M = | Dot(N,E-P)*I - E*N^T -(Dot(N,E-P)*I - E*N^T)*E | | -N^t Dot(N,E) | +- -+ where E is the eye point, P is a point on the plane, and N is a unit-length plane normal.
          Parameters:
          rkNormal - normal vector
          rkPoint - point
          rkEye - eye vector
        • MakeReflection

          public void MakeReflection​(Vector3d rkNormal,
                                     Vector3d rkPoint)
          Deprecated.
          reflection matrix through a specified plane +- -+ M = | I-2*N*N^T 2*Dot(N,P)*N | | 0^T 1 | +- -+ where P is a point on the plane and N is a unit-length plane normal.
          Parameters:
          rkNormal - normal vector
          rkPoint - point
        • MakeZero

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

          public Matrix4d makeZero()
          make this the zero matrix
        • Mult

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

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

          public void Mult​(Matrix4d kM1,
                           Matrix4d kM2)
          Deprecated.
          Multiply the two input matrices, setting this: this = kM1 * kM2
          Parameters:
          kM1 - first input matrix
          kM2 - second input matrix
        • mult

          public static Matrix4d mult​(Matrix4d kM1,
                                      Matrix4d kM2)
          Multiply the two input matrices, setting this: this = kM1 * kM2
          Parameters:
          kM1 - first input matrix
          kM2 - second input matrix
        • Mult

          public void Mult​(Vector4d kIn,
                           Vector4d kOut)
          Deprecated.
          matrix times vector: kOut = this * kIn
          Parameters:
          kIn - input vector
          kOut - output vector = this * v
        • mult

          public void mult​(Vector4d kIn,
                           Vector4d kOut)
          matrix times vector: kOut = this * kIn
          Parameters:
          kIn - input vector
          kOut - output vector = this * v
        • mult

          public Vector4d mult​(Vector4d kIn)
          matrix times vector: kOut = this * kIn
          Parameters:
          kIn - input vector
          kOut - output vector = this * v
        • MultLeft

          public void MultLeft​(Matrix4d kM)
          Deprecated.
          Multiply the two input matrices, setting this: this = kM1 * this
          Parameters:
          kM - first input matrix
        • multLeft

          public Matrix4d multLeft​(Matrix4d kM)
          Multiply the two input matrices, setting this: this = kM1 * this
          Parameters:
          kM - first input matrix
        • MultLeft

          public void MultLeft​(Vector4d kIn,
                               Vector4d rkOut)
          Deprecated.
          matrix times vector: v^T * this
          Parameters:
          kIn - vector
          rkOut - vector = kIn^T * this
        • multLeft

          public void multLeft​(Vector4d kIn,
                               Vector4d rkOut)
          matrix times vector: v^T * this
          Parameters:
          kIn - vector
          rkOut - vector = kIn^T * this
        • multLeft

          public Vector4d multLeft​(Vector4d kIn)
          matrix times vector: v^T * this
          Parameters:
          kIn - vector
          rkOut - vector = kIn^T * this
        • MultRight

          public void MultRight​(Vector4d kIn,
                                Vector4d kOut)
          Deprecated.
          matrix times vector: kOut = this * kIn
          Parameters:
          kIn - input vector
          kOut - output vector = this * v
        • multRight

          public void multRight​(Vector4d kIn,
                                Vector4d kOut)
          matrix times vector: kOut = this * kIn
          Parameters:
          kIn - input vector
          kOut - output vector = this * v
        • multRight

          public Vector4d multRight​(Vector4d kIn)
          matrix times vector: kOut = this * kIn
          Parameters:
          kIn - input vector
          kOut - output vector = this * v
        • QForm

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

          public double qForm​(Vector4d rkU,
                              Vector4d rkV)
          Calculate and return u^T*M*v
          Parameters:
          rkU - u
          rkV - v
          Returns:
          u^T*M*v
        • Set

          public final void Set​(double fM00,
                                double fM01,
                                double fM02,
                                double fM03,
                                double fM10,
                                double fM11,
                                double fM12,
                                double fM13,
                                double fM20,
                                double fM21,
                                double fM22,
                                double fM23,
                                double fM30,
                                double fM31,
                                double fM32,
                                double fM33)
          Deprecated.
          input Mrc is in row r, column c.
          Parameters:
          fM00 - matrix[0] entry
          fM01 - matrix[1] entry
          fM02 - matrix[2] entry
          fM03 - matrix[3] entry
          fM10 - matrix[4] entry
          fM11 - matrix[5] entry
          fM12 - matrix[6] entry
          fM13 - matrix[7] entry
          fM20 - matrix[8] entry
          fM21 - matrix[9] entry
          fM22 - matrix[10] entry
          fM23 - matrix[11] entry
          fM30 - matrix[12] entry
          fM31 - matrix[13] entry
          fM32 - matrix[14] entry
          fM33 - matrix[15] entry
        • set

          public Matrix4d set​(double fM00,
                              double fM01,
                              double fM02,
                              double fM03,
                              double fM10,
                              double fM11,
                              double fM12,
                              double fM13,
                              double fM20,
                              double fM21,
                              double fM22,
                              double fM23,
                              double fM30,
                              double fM31,
                              double fM32,
                              double fM33)
          input Mrc is in row r, column c.
          Parameters:
          fM00 - matrix[0] entry
          fM01 - matrix[1] entry
          fM02 - matrix[2] entry
          fM03 - matrix[3] entry
          fM10 - matrix[4] entry
          fM11 - matrix[5] entry
          fM12 - matrix[6] entry
          fM13 - matrix[7] entry
          fM20 - matrix[8] entry
          fM21 - matrix[9] entry
          fM22 - matrix[10] entry
          fM23 - matrix[11] entry
          fM30 - matrix[12] entry
          fM31 - matrix[13] entry
          fM32 - matrix[14] entry
          fM33 - matrix[15] entry
        • Set

          public final void Set​(int iRow,
                                int iCol,
                                double fValue)
          Deprecated.
          Set member access
          Parameters:
          iRow - row to set
          iCol - column to set
          fValue - new value
        • set

          public Matrix4d set​(int iRow,
                              int iCol,
                              double fValue)
          Set member access
          Parameters:
          iRow - row to set
          iCol - column to set
          fValue - new value
        • TimesTranspose

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

          public Matrix4d timesTranspose​(Matrix4d kM)
          Multiply this matrix by transpose of the input matrix, setting this: this = this * M^T
          Parameters:
          kM - matrix
        • 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, setting this, this = this^T
        • transpose

          public Matrix4d transpose()
          Transpose this matrix, setting this, this = this^T
        • Transpose

          public void Transpose​(Matrix4d kM)
          Deprecated.
          Transpose the input matrix, setting this, this = kM^T
        • transpose

          public static Matrix4d transpose​(Matrix4d kM)
          Transpose the input matrix, setting this, this = kM^T
        • TransposeTimes

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

          public Matrix4d transposeTimes​(Matrix4d kM)
          Transpose this matrix and multiply by input, setting this: this = this^T * M
          Parameters:
          kM - matrix
        • TransposeTimes

          public void TransposeTimes​(Matrix4d kM1,
                                     Matrix4d kM2)
          Deprecated.
          Transpose M1 and multiply by M2, setting this: this = M1^T * M2
          Parameters:
          kM1 - matrix
          kM2 - matrix
        • transposeTimes

          public static Matrix4d transposeTimes​(Matrix4d kM1,
                                                Matrix4d kM2)
          Transpose M1 and multiply by M2, setting this: this = M1^T * M2
          Parameters:
          kM1 - matrix
          kM2 - matrix