Class Matrix2
Object
Matrix2
- All Implemented Interfaces:
Serializable,Cloneable,Matrix,Cloneable,XMatrix
- Since:
- 2.2
- Author:
- Martin Desruisseaux (IRD)
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptiondoubleThe first matrix element in the first row.doubleThe second matrix element in the first row.doubleThe first matrix element in the second row.doubleThe second matrix element in the second row.static final intThe matrix size, which is 2. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double scalar) Performs an in-place scalar addition.voidSet to the scalar addition ofscalar+matrixvoidSet to the matrix addition ofthis+matrix.voidSet to the matrix addition ofmatrix1+matrix2.clone()Returns a clone of this matrix.doubleComputes the determinantbooleanReturnstrueif the specified object is of typeMatrix2and all of the data members are equal to the corresponding data members in this matrix.booleanCompares the element values.voidgetColumn(int column, double[] array) Extract col to provided array.final doublegetElement(int row, int col) Returns the element at the specified index.final intReturns the number of colmuns in this matrix, which is always 2 in this implementation.final intReturns the number of rows in this matrix, which is always 2 in this implementation.voidgetRow(int row, double[] array) Extract row to provided arrayinthashCode()Returns a hash code value based on the data values in this object.final voidinvert()Inverts this matrix in place.voidSet to the inverse of the provided matrix.final booleanisAffine()Returnstrueif this matrix is an affine transform.final booleanReturnstrueif this matrix is an identity matrix.final booleanisIdentity(double tolerance) Returnstrueif this matrix is an identity matrix using the provided tolerance.voidmul(double scalar) Sets this matrix to the result of multiplying itself with the provided scalar.voidSets the value of this matrix to the result of multiplying the provided scalar and matrix.voidSets the value of this matrix to the result of multiplying itself with the specified matrix.voidSets the value of this matrix to the result of multiplying matrix1 and matrix2.final voidSets the value of this matrix to the result of multiplying itself with the specified matrix.final voidnegate()Negates the value of this matrix:this = -this.voidNegates the value of this matrix:this = -matrix.voidsetColumn(int column, double... values) Sets the value of the column using an array of values.final voidsetElement(int row, int col, double value) Modifies the value at the specified row and column of this matrix.final voidSets this matrix to the identity matrix.voidsetRow(int row, double... values) Sets the value of the row using an array of values.final voidsetZero()Sets all the values in this matrix to zero.voidsub(double scalar) In-place matrix subtraction:this - scalar.voidSet to the difference ofscalar - matrix2.voidIn-place matrix subtraction:this - matrix.voidSet to the difference ofmatrix1 - matrix2.toString()Returns a string representation of this matrix.final voidSets the value of this matrix to its transpose.voidSet to the transpose of the provided matrix.
-
Field Details
-
SIZE
public static final int SIZEThe matrix size, which is 2.- See Also:
-
m00
public double m00The first matrix element in the first row. -
m01
public double m01The second matrix element in the first row. -
m10
public double m10The first matrix element in the second row. -
m11
public double m11The second matrix element in the second row.
-
-
Constructor Details
-
Matrix2
public Matrix2()Creates a new identity matrix. -
Matrix2
public Matrix2(double m00, double m01, double m10, double m11) Creates a new matrix initialized to the specified values. -
Matrix2
-
-
Method Details
-
getNumRow
public final int getNumRow()Returns the number of rows in this matrix, which is always 2 in this implementation. -
getNumCol
public final int getNumCol()Returns the number of colmuns in this matrix, which is always 2 in this implementation. -
getElement
public final double getElement(int row, int col) Returns the element at the specified index.- Specified by:
getElementin interfaceMatrix- Specified by:
getElementin interfaceXMatrix- Parameters:
row- The row number to be retrieved (zero indexed).col- The column number to be retrieved (zero indexed).- Returns:
- The value at the indexed element.
-
setElement
public final void setElement(int row, int col, double value) Modifies the value at the specified row and column of this matrix.- Specified by:
setElementin interfaceMatrix- Parameters:
row- The row number to be retrieved (zero indexed).col- The column number to be retrieved (zero indexed).value- The new matrix element value.
-
setZero
public final void setZero()Sets all the values in this matrix to zero. -
setIdentity
public final void setIdentity()Sets this matrix to the identity matrix.- Specified by:
setIdentityin interfaceXMatrix
-
isIdentity
public final boolean isIdentity()Returnstrueif this matrix is an identity matrix.- Specified by:
isIdentityin interfaceMatrix- Returns:
trueif this matrix is an identity matrix.
-
isIdentity
public final boolean isIdentity(double tolerance) Returnstrueif this matrix is an identity matrix using the provided tolerance. This method is equivalent to computing the difference between this matrix and an identity matrix of identical size, and returningtrueif and only if all differences are smaller than or equal totolerance.- Specified by:
isIdentityin interfaceXMatrix- Parameters:
tolerance- The tolerance value.- Returns:
trueif this matrix is close enough to the identity matrix given the tolerance value.
-
isAffine
public final boolean isAffine()Returnstrueif this matrix is an affine transform. A transform is affine if the matrix is square and last row contains only zeros, except in the last column which contains 1. -
negate
public final void negate()Negates the value of this matrix:this = -this. -
negate
Description copied from interface:XMatrixNegates the value of this matrix:this = -matrix. -
transpose
public final void transpose()Sets the value of this matrix to its transpose. -
transpose
Description copied from interface:XMatrixSet to the transpose of the provided matrix. -
invert
public final void invert()Inverts this matrix in place. -
invert
Description copied from interface:XMatrixSet to the inverse of the provided matrix.- Specified by:
invertin interfaceXMatrix- Parameters:
matrix- The matrix that is to be inverted. Not modified.- Throws:
SingularMatrixException- if this matrix is not invertible.
-
multiply
Description copied from interface:XMatrixSets the value of this matrix to the result of multiplying itself with the specified matrix. In other words, performsthis=this×matrix. In the context of coordinate transformations, this is equivalent toAffineTransform.concatenate: first transforms by the supplied transform and then transform the result by the original transform. -
equals
Compares the element values. -
equals
Returnstrueif the specified object is of typeMatrix2and all of the data members are equal to the corresponding data members in this matrix. -
hashCode
public int hashCode()Returns a hash code value based on the data values in this object. -
toString
Returns a string representation of this matrix. The returned string is implementation dependent. It is usually provided for debugging purposes only. -
clone
Returns a clone of this matrix. -
getRow
public void getRow(int row, double[] array) Description copied from interface:XMatrixExtract row to provided array -
setRow
public void setRow(int row, double... values) Description copied from interface:XMatrixSets the value of the row using an array of values. -
getColumn
public void getColumn(int column, double[] array) Description copied from interface:XMatrixExtract col to provided array. -
setColumn
public void setColumn(int column, double... values) Description copied from interface:XMatrixSets the value of the column using an array of values. -
add
public void add(double scalar) Description copied from interface:XMatrixPerforms an in-place scalar addition. -
add
Description copied from interface:XMatrixSet to the scalar addition ofscalar+matrix -
add
Description copied from interface:XMatrixSet to the matrix addition ofthis+matrix. -
add
Description copied from interface:XMatrixSet to the matrix addition ofmatrix1+matrix2. -
determinate
public double determinate()Description copied from interface:XMatrixComputes the determinant- Specified by:
determinatein interfaceXMatrix
-
mul
public void mul(double scalar) Description copied from interface:XMatrixSets this matrix to the result of multiplying itself with the provided scalar. -
mul
Description copied from interface:XMatrixSets the value of this matrix to the result of multiplying the provided scalar and matrix. -
mul
Description copied from interface:XMatrixSets the value of this matrix to the result of multiplying itself with the specified matrix. In other words, performsthis=this×matrix. In the context of coordinate transformations, this is equivalent toAffineTransform.concatenate: first transforms by the supplied transform and then transform the result by the original transform. -
mul
Description copied from interface:XMatrixSets the value of this matrix to the result of multiplying matrix1 and matrix2. -
sub
public void sub(double scalar) Description copied from interface:XMatrixIn-place matrix subtraction:this - scalar. -
sub
Description copied from interface:XMatrixSet to the difference ofscalar - matrix2. -
sub
Description copied from interface:XMatrixIn-place matrix subtraction:this - matrix. -
sub
Description copied from interface:XMatrixSet to the difference ofmatrix1 - matrix2.
-