Class Matrix3f
- java.lang.Object
-
- WildMagic.LibFoundation.Mathematics.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
-
-
Constructor Summary
Constructors Constructor Description Matrix3f()
Constructor, defaults to zero-matrix:Matrix3f(boolean bZero)
If bZero is true, create the zero matrix.Matrix3f(float[] afEntry, boolean bRowMajor)
Create a matrix from an array of numbers.Matrix3f(float fM00, float fM11, float fM22)
create a diagonal matrixMatrix3f(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.Matrix3f(Matrix3f rkM)
copy constructorMatrix3f(Vector3f[] akV, boolean bColumns)
Create matrices based on vector input.Matrix3f(Vector3f rkAxis, float fAngle)
Create rotation matrices (positive angle - counterclockwise).Matrix3f(Vector3f rkU, Vector3f rkV)
create a tensor product U*V^TMatrix3f(Vector3f rkU, Vector3f rkV, Vector3f rkW, boolean bColumns)
Create matrices based on vector input.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Matrix3f
add(float fM00, float fM01, float fM02, float fM10, float fM11, float fM12, float fM20, float fM21, float fM22)
Matrix3f
add(Matrix3f kMat)
this = this + kMatstatic Matrix3f
add(Matrix3f kMat1, Matrix3f kMat2)
Add to this matrix = kMat1 + kMat2.Matrix3f
adjoint()
Compute the adjoint of this matrix: this = Adjoint(this)Matrix3f
copy(Matrix3f rkM)
Copy this = rkMfloat
determinant()
Return the determinant of this matrix.Matrix3f
diagonalTimes(Vector3f kDiag)
Compute the diagonal vector times this matrix: this = D*Mstatic boolean
eigenDecomposition(Matrix3f rkRot, Matrix3f rkDiag)
Factor M = R*D*R^T.boolean
equals(java.lang.Object kObject)
Matrix3f
fromAxisAngle(Vector3f rkAxis, float fAngle)
Create a rotation matrix from an axis and angle in radians.float
get(int iIndex)
Get member accessfloat
get(int iRow, int iCol)
Get member accessVector3f
getColumn(int iCol)
void
getColumn(int iCol, Vector3f kResult)
Get member accessvoid
getColumnMajor(float[] afCMajor)
Get member access.void
getData(float[] afData)
Get member access.Matrix3f
identity()
make this the identity matrixMatrix3f
inverse()
Invert a 3x3 using cofactors.static Matrix3f
inverse(Matrix3f kM)
Invert a 3x3 using cofactors.static void
main(java.lang.String[] args)
Matrix3f
makeDiagonal(float fM00, float fM11, float fM22)
Create a diagonal matrix:Matrix3f
makeTensorProduct(Vector3f rkU, Vector3f rkV)
create a tensor product U*V^TMatrix3f
mult(Matrix3f kM)
Multiply this matrix to the input matrix: this = this * kM.static Matrix3f
mult(Matrix3f kM1, Matrix3f kM2)
Multiply this matrix to the input matrix: this = kM1 * kM2.Vector3f
mult(Vector3f kV)
void
mult(Vector3f kV, Vector3f kResult)
kResult = this * kVMatrix3f
multLeft(Matrix3f kM)
this = kM * thisVector3f
multLeft(Vector3f kV)
void
multLeft(Vector3f kV, Vector3f kResult)
matrix times vector: kResult = v^T * thisVector3f
multRight(Vector3f kV)
void
multRight(Vector3f kV, Vector3f kResult)
Matrix times vector: Result = this * vMatrix3f
orthonormalize()
The matrix must be a rotation for these functions to be valid.float
qForm(Vector3f rkU, Vector3f rkV)
Calculate and return u^T*M*vprivate 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.Matrix3f
scale(float fScalar)
this = this * fScalarMatrix3f
set(float[] afEntry, boolean bRowMajor)
Create a matrix from an array of numbers.Matrix3f
set(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.Matrix3f
set(int iIndex, float fValue)
Matrix3f
set(int iRow, int iCol, float fValue)
Set the values of this.Matrix3f
setColumn(int iCol, Vector3f kV)
Set member accessstatic boolean
test()
static boolean
test(int count)
Matrix3f
timesDiagonal(Vector3f kDiag)
Compute this matrix times the diagonal vector: this = M*DMatrix3f
timesTranspose(Matrix3f kM)
Multiply this matrix by transpose of the input matrix: this = this * M^Tfloat
toAxisAngle(Vector3f rkAxis)
The matrix must be a rotation for these functions to be valid.java.lang.String
toString()
Returns a string representation of the matrix values.Matrix3f
transpose()
Transpose this matrix: this = this^TMatrix3f
transposeTimes(Matrix3f kM)
Transpose this matrix and multiply by input: this = this^T * Mprivate static boolean
tridiagonalize(Matrix3f rkRot, float[] afDiag, float[] afSubd)
Householder reduction T = Q^t M Q Input: mat, symmetric 3x3 matrix M Output:Matrix3f
zero()
make this the zero matrix
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
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 valuefM11
- 1-diagonal valuefM22
- 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] entryfM01
- matrix[1] entryfM02
- matrix[2] entryfM10
- matrix[3] entryfM11
- matrix[4] entryfM12
- matrix[5] entryfM20
- matrix[6] entryfM21
- matrix[7] entryfM22
- 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 matrixbRowMajor
- 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 axisfAngle
- rotation angle in radians
-
Matrix3f
public Matrix3f(Vector3f rkU, Vector3f rkV)
create a tensor product U*V^T- Parameters:
rkU
- U-VectorrkV
- 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 vector1rkV
- input vector2rkW
- input vector3bColumns
- 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)
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 TafSubd
- subd, subdiagonal entries of T (T is symmetric)
-
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 static Matrix3f add(Matrix3f kMat1, Matrix3f kMat2)
Add to this matrix = kMat1 + kMat2.- Parameters:
kMat1
-kMat2
-
-
adjoint
public Matrix3f 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.
-
diagonalTimes
public Matrix3f diagonalTimes(Vector3f kDiag)
Compute the diagonal vector times this matrix: this = D*M- Parameters:
kDiag
- diagonal vector
-
fromAxisAngle
public Matrix3f fromAxisAngle(Vector3f rkAxis, float fAngle)
Create a rotation matrix from an axis and angle in radians.- Parameters:
rkAxis
- rotation axisfAngle
- 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, Vector3f kResult)
Get member access- Parameters:
iCol
- column to getkResult
- column vector values
-
getColumn
public Vector3f getColumn(int iCol)
-
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 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 static Matrix3f inverse(Matrix3f kM)
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 Matrix3f makeDiagonal(float fM00, float fM11, float fM22)
Create a diagonal matrix:- Parameters:
fM00
- matrix[0] entryfM11
- matrix[4] entryfM22
- matrix[8] entry
-
identity
public Matrix3f identity()
make this the identity matrix
-
makeTensorProduct
public Matrix3f makeTensorProduct(Vector3f rkU, Vector3f rkV)
create a tensor product U*V^T- Parameters:
rkU
- U-VectorrkV
- V-Vector
-
zero
public Matrix3f zero()
make this the zero matrix
-
mult
public Matrix3f mult(Matrix3f kM)
Multiply this matrix to the input matrix: this = this * kM.- Parameters:
kM
- input matrix
-
mult
public static Matrix3f mult(Matrix3f kM1, Matrix3f kM2)
Multiply this matrix to the input matrix: this = kM1 * kM2.- Parameters:
kM1
- first input matrixkM2
- second input matrix
-
mult
public void mult(Vector3f kV, Vector3f kResult)
kResult = this * kV- Parameters:
kV
-kResult
-
-
multLeft
public void multLeft(Vector3f kV, Vector3f kResult)
matrix times vector: kResult = v^T * this- Parameters:
kV
- vectorkResult
- = v^T * this
-
multRight
public void multRight(Vector3f kV, Vector3f kResult)
Matrix times vector: Result = this * v- Parameters:
kV
- vectorkResult
- = this * v- See Also:
#Mult(Vector3f kV, Vector3f kResult)
-
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)
Calculate and return u^T*M*v- Parameters:
rkU
- urkV
- v- Returns:
- u^T*M*v
-
scale
public Matrix3f scale(float fScalar)
this = this * fScalar- Parameters:
fScalar
-- Returns:
- this
-
set
public Matrix3f set(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] entryfM01
- matrix[1] entryfM02
- matrix[2] entryfM10
- matrix[3] entryfM11
- matrix[4] entryfM12
- matrix[5] entryfM20
- matrix[6] entryfM21
- matrix[7] entryfM22
- matrix[8] entry
-
set
public Matrix3f set(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 matrixbRowMajor
- when true copy in row major order.
-
set
public Matrix3f set(int iIndex, float fValue)
- Parameters:
iIndex
- matrix index
-
set
public final Matrix3f set(int iRow, int iCol, float fValue)
Set the values of this.- Parameters:
iRow
- row-valueiCol
- column-valuefValue
- matrix[iIndex] new value
-
setColumn
public Matrix3f setColumn(int iCol, Vector3f kV)
Set member access- Parameters:
iCol
- column to setkV
- new column vector values
-
timesDiagonal
public Matrix3f timesDiagonal(Vector3f kDiag)
Compute this matrix times the diagonal vector: this = M*D- Parameters:
kDiag
- diagonal vector- Returns:
- this
-
timesTranspose
public Matrix3f timesTranspose(Matrix3f kM)
Multiply this matrix by transpose of the input matrix: this = this * M^T- Parameters:
kM
- matrix
-
toAxisAngle
public float toAxisAngle(Vector3f rkAxis)
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
-
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 Matrix3f transpose()
Transpose this matrix: this = this^T- Returns:
- this
-
transposeTimes
public Matrix3f transposeTimes(Matrix3f kM)
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 classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
-
test
public static boolean test()
-
test
public static boolean test(int count)
-
-