Class Matrix4d
- java.lang.Object
-
- WildMagic.LibFoundation.Mathematics.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 Summary
Fields Modifier and Type Field Description static Matrix4d
IDENTITY
Identity matrix:double
M00
Matrix data:double
M01
Matrix data:double
M02
Matrix data:double
M03
Matrix data:double
M10
double
M11
double
M12
double
M13
double
M20
double
M21
double
M22
double
M23
double
M30
double
M31
double
M32
double
M33
private static long
serialVersionUID
static Matrix4d
ZERO
Zero matrix:
-
Constructor Summary
Constructors Constructor Description Matrix4d()
Create the zero matrix.Matrix4d(boolean bZero)
If bZero is true, create the zero matrix.Matrix4d(double[] afEntry, boolean bRowMajor)
Create a matrix from an array of numbers.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.Matrix4d(Matrix4d rkM)
copy constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix4d
adjoint()
Compute the adjoint of this matrix, setting this: this = Adjoint(this).Matrix4d
copy(Matrix4d rkM)
copy, overwrite this.double
determinant()
Return the determinant of this matrix.boolean
equals(java.lang.Object kObject)
double
get(int iRow, int iCol)
Get member accessvoid
getColumnMajor(double[] afCMajor)
Get member access.void
getData(double[] afData)
Get member access.void
getData(float[] afData)
Get member access.Matrix4d
identity()
make this the identity matrixMatrix4d
inverse()
Invert a 4x4 using cofactors.static Matrix4d
inverse(Matrix4d kM)
Invert a 4x4 using cofactors.Matrix4d
makeObliqueProjection(Vector3d rkNormal, Vector3d rkPoint, Vector3d rkDirection)
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.Matrix4d
makePerspectiveProjection(Vector3d rkNormal, Vector3d rkPoint, Vector3d rkEye)
+- -+ 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.Matrix4d
makeReflection(Vector3d rkNormal, Vector3d rkPoint)
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.Matrix4d
makeZero()
make this the zero matrixMatrix4d
mult(Matrix4d kM)
Multiply this matrix to the input matrix: this = this * kMstatic Matrix4d
mult(Matrix4d kM1, Matrix4d kM2)
Multiply the two input matrices, setting this: this = kM1 * kM2Vector4d
mult(Vector4d kIn)
matrix times vector: kOut = this * kInvoid
mult(Vector4d kIn, Vector4d kOut)
matrix times vector: kOut = this * kInMatrix4d
multLeft(Matrix4d kM)
Multiply the two input matrices, setting this: this = kM1 * thisVector4d
multLeft(Vector4d kIn)
matrix times vector: v^T * thisvoid
multLeft(Vector4d kIn, Vector4d rkOut)
matrix times vector: v^T * thisVector4d
multRight(Vector4d kIn)
matrix times vector: kOut = this * kInvoid
multRight(Vector4d kIn, Vector4d kOut)
matrix times vector: kOut = this * kIndouble
qForm(Vector4d rkU, Vector4d rkV)
Calculate and return u^T*M*vMatrix4d
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.Matrix4d
set(int iRow, int iCol, double fValue)
Set member accessMatrix4d
timesTranspose(Matrix4d kM)
Multiply this matrix by transpose of the input matrix, setting this: this = this * M^Tjava.lang.String
toString()
Returns a string representation of the matrix values.Matrix4d
transpose()
Transpose this matrix, setting this, this = this^Tstatic Matrix4d
transpose(Matrix4d kM)
Transpose the input matrix, setting this, this = kM^TMatrix4d
transposeTimes(Matrix4d kM)
Transpose this matrix and multiply by input, setting this: this = this^T * Mstatic Matrix4d
transposeTimes(Matrix4d kM1, Matrix4d kM2)
Transpose M1 and multiply by M2, setting this: this = M1^T * M2
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
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] entryfM01
- matrix[1] entryfM02
- matrix[2] entryfM03
- matrix[3] entryfM10
- matrix[4] entryfM11
- matrix[5] entryfM12
- matrix[6] entryfM13
- matrix[7] entryfM20
- matrix[8] entryfM21
- matrix[9] entryfM22
- matrix[10] entryfM23
- matrix[11] entryfM30
- matrix[12] entryfM31
- matrix[13] entryfM32
- matrix[14] entryfM33
- 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 matrixbRowMajor
- when true copy in row major order.
-
Matrix4d
public Matrix4d(Matrix4d rkM)
copy constructor- Parameters:
rkM
- matrix to copy
-
-
Method Detail
-
adjoint
public Matrix4d adjoint()
Compute the adjoint of this matrix, setting this: this = Adjoint(this).
-
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 classjava.lang.Object
-
get
public final double get(int iRow, int iCol)
Get member access- Parameters:
iRow
- row to getiCol
- column to get- Returns:
- value at m_afEntry[iRow*4 + iCol];
-
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)
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 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 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
-
identity
public Matrix4d identity()
make this the identity matrix
-
makeObliqueProjection
public Matrix4d makeObliqueProjection(Vector3d rkNormal, Vector3d rkPoint, Vector3d rkDirection)
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) < 0 (projection is onto the "positive side" of the plane).- Parameters:
rkNormal
- normal vectorrkPoint
- pointrkDirection
- direction vector
-
makePerspectiveProjection
public Matrix4d makePerspectiveProjection(Vector3d rkNormal, Vector3d rkPoint, Vector3d rkEye)
+- -+ 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 vectorrkPoint
- pointrkEye
- eye vector
-
makeReflection
public Matrix4d makeReflection(Vector3d rkNormal, Vector3d rkPoint)
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 vectorrkPoint
- point
-
makeZero
public Matrix4d makeZero()
make this the zero matrix
-
mult
public Matrix4d mult(Matrix4d kM)
Multiply this matrix to the input matrix: this = this * kM- Parameters:
kM
- 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 matrixkM2
- second input matrix
-
mult
public void mult(Vector4d kIn, Vector4d kOut)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
mult
public Vector4d mult(Vector4d kIn)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
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)
matrix times vector: v^T * this- Parameters:
kIn
- vectorrkOut
- vector = kIn^T * this
-
multLeft
public Vector4d multLeft(Vector4d kIn)
matrix times vector: v^T * this- Parameters:
kIn
- vectorrkOut
- vector = kIn^T * this
-
multRight
public void multRight(Vector4d kIn, Vector4d kOut)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
multRight
public Vector4d multRight(Vector4d kIn)
matrix times vector: kOut = this * kIn- Parameters:
kIn
- input vectorkOut
- output vector = this * v
-
qForm
public double qForm(Vector4d rkU, Vector4d rkV)
Calculate and return u^T*M*v- Parameters:
rkU
- urkV
- v- Returns:
- u^T*M*v
-
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] entryfM01
- matrix[1] entryfM02
- matrix[2] entryfM03
- matrix[3] entryfM10
- matrix[4] entryfM11
- matrix[5] entryfM12
- matrix[6] entryfM13
- matrix[7] entryfM20
- matrix[8] entryfM21
- matrix[9] entryfM22
- matrix[10] entryfM23
- matrix[11] entryfM30
- matrix[12] entryfM31
- matrix[13] entryfM32
- matrix[14] entryfM33
- matrix[15] entry
-
set
public Matrix4d set(int iRow, int iCol, double fValue)
Set member access- Parameters:
iRow
- row to setiCol
- column to setfValue
- new value
-
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 classjava.lang.Object
- Returns:
- string representation of the matrix values.
-
transpose
public Matrix4d transpose()
Transpose this matrix, setting this, this = this^T
-
transpose
public static Matrix4d transpose(Matrix4d kM)
Transpose the input matrix, setting this, this = kM^T
-
transposeTimes
public Matrix4d transposeTimes(Matrix4d kM)
Transpose this matrix and multiply by input, setting this: this = this^T * M- Parameters:
kM
- matrix
-
-