Class Matrix2f
- java.lang.Object
-
- WildMagic.LibFoundation.Mathematics.Matrix2f
-
- All Implemented Interfaces:
java.io.Serializable
public class Matrix2f extends java.lang.Object implements java.io.SerializableMatrix 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
-
-
Constructor Summary
Constructors Constructor Description Matrix2f()Constructor, defaults to zero-matrix:Matrix2f(boolean bZero)If bZero is true, create the zero matrix.Matrix2f(float fAngle)Create rotation matrices (positive angle - counterclockwise).Matrix2f(float[] afEntry, boolean bRowMajor)Create a matrix from an array of numbers.Matrix2f(float fM00, float fM11)create a diagonal matrixMatrix2f(float fM00, float fM01, float fM10, float fM11)input Mrc is in row r, column c.Matrix2f(Matrix2f rkM)copy constructorMatrix2f(Vector2f[] akV, boolean bColumns)Create matrices based on vector input.Matrix2f(Vector2f rkU, Vector2f rkV)create a tensor product U*V^TMatrix2f(Vector2f rkU, Vector2f rkV, boolean bColumns)Create matrices based on vector input.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix2fadd(float fM00, float fM01, float fM10, float fM11)Add to this matrix.Matrix2fadjoint()Compute the adjoint of this matrix: this = Adjoint(this)Matrix2fcopy(Matrix2f rkM)Set the values of this.floatdeterminant()Return the determinant of this matrix.voideigenDecomposition(Matrix2f rkRot, Matrix2f rkDiag)Factor M = R*D*R^T.Matrix2ffromAngle(float fAngle)Create a rotation matrix from an angle in radians.floatget(int iIndex)Get member accessfloatget(int iRow, int iCol)Get member accessvoidgetColumn(int iCol, Vector2f kResult)Get member accessvoidgetColumnMajor(float[] afCMajor)Get member access.voidgetData(float[] afData)Get member access.Matrix2fidentity()make this the identity matrixMatrix2finverse()Invert a 3x3 using cofactors.static Matrix2finverse(Matrix2f kM)Invert using cofactors.Matrix2fmakeDiagonal(float fM00, float fM11)Create a diagonal matrix:Matrix2fmakeTensorProduct(Vector2f rkU, Vector2f rkV)create a tensor product U*V^TMatrix2fmakeZero()make this the zero matrixMatrix2fmult(Matrix2f kM)Multiply this matrix to the input matrix: this = this * kM.static Matrix2fmult(Matrix2f kM1, Matrix2f kM2)Multiply this matrix to the input matrix: this = kM1 * kM2.Vector2fmult(Vector2f kV)Matrix times vector: Result = this * vvoidmult(Vector2f kV, Vector2f kResult)Matrix times vector: Result = this * vMatrix2fmultLeft(Matrix2f kM)Multiply this matrix to the input matrix: this = kM * this.Vector2fmultLeft(Vector2f kV)matrix times vector: kResult = v^T * thisvoidmultLeft(Vector2f kV, Vector2f kResult)matrix times vector: kResult = v^T * thisVector2fmultRight(Vector2f kV)Matrix times vector: Result = this * vvoidmultRight(Vector2f kV, Vector2f kResult)Matrix times vector: Result = this * vMatrix2forthonormalize()The matrix must be a rotation for these functions to be valid.floatqForm(Vector2f rkU, Vector2f rkV)Calculate and return u^T*M*vMatrix2fscale(float fScalar)Multiply this matrix by the scalar input: this = this * fScalar.Matrix2fset(float fM00, float fM01, float fM10, float fM11)input Mrc is in row r, column c.Matrix2fset(int iIndex, float fValue)Matrix2fset(int iRow, int iCol, float fValue)Set the values of this.Matrix2fsetColumn(int iCol, Vector2f kV)Set member accessMatrix2ftimesTranspose(Matrix2f kM)Multiply this matrix by transpose of the input matrix: this = this * M^TfloattoAngle()The matrix must be a rotation.java.lang.StringtoString()Returns a string representation of the matrix values.Matrix2ftranspose()Transpose this matrix: this = this^TMatrix2ftransposeTimes(Matrix2f kM)Transpose this matrix and multiply by input: this = this^T * M
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
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 valuefM11- 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] entryfM01- matrix[1] entryfM10- matrix[2] entryfM11- 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 matrixbRowMajor- 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-VectorrkV- 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 vector1rkV- input vector2bColumns- 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)
-
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-valueiCol- column-value- Returns:
- matrix[iRow*3 + iCol]
-
getColumn
public void getColumn(int iCol, Vector2f kResult)Get member access- Parameters:
iCol- column to getkResult- 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] entryfM11- 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-VectorrkV- 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 matrixkM2- second input matrix
-
mult
public void mult(Vector2f kV, Vector2f kResult)
Matrix times vector: Result = this * v- Parameters:
kV- vectorkResult- = this * v
-
mult
public Vector2f mult(Vector2f kV)
Matrix times vector: Result = this * v- Parameters:
kV- vectorkResult- = 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- vectorkResult- = v^T * this
-
multLeft
public Vector2f multLeft(Vector2f kV)
matrix times vector: kResult = v^T * this- Parameters:
kV- vectorkResult- = v^T * this
-
multRight
public void multRight(Vector2f kV, Vector2f kResult)
Matrix times vector: Result = this * v- Parameters:
kV- vectorkResult- = this * v
-
multRight
public Vector2f multRight(Vector2f kV)
Matrix times vector: Result = this * v- Parameters:
kV- vectorkResult- = 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- urkV- 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] entryfM01- matrix[1] entryfM10- matrix[2] entryfM11- 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-valueiCol- column-valuefValue- matrix[iIndex] new value
-
setColumn
public Matrix2f setColumn(int iCol, Vector2f kV)
Set member access- Parameters:
iCol- column to setkV- 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:
toStringin classjava.lang.Object- Returns:
- string representation of the matrix values.
-
transpose
public Matrix2f transpose()
Transpose this matrix: this = this^T
-
-