Class Matrix2
-
- All Implemented Interfaces:
Serializable,Cloneable,LenientComparable,Matrix
public final class Matrix2 extends MatrixSIS
A matrix of fixed 2×2 size, typically resulting fromMathTransform2Dderivative computation. The matrix members are:┌ ┐ │ m00 m01 │ │ m10 m11 │ └ ┘
- Since:
- 0.4
- See Also:
Matrix1,Matrix3,Matrix4, Serialized Form
Defined in the
sis-referencingmodule
-
-
Field Summary
Fields Modifier and Type Field Description doublem00The first matrix element in the first row.doublem01The second matrix element in the first row.doublem10The first matrix element in the second row.doublem11The second matrix element in the second row.static intSIZEThe matrix size, which is 2.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Matrix2castOrCopy(Matrix matrix)Casts or copies the given matrix to aMatrix2implementation.booleanequals(Object object)Returnstrueif the specified object is of typeMatrix2and all of the data members are equal to the corresponding data members in this matrix.doublegetElement(int row, int column)Retrieves the value at the specified row and column of this matrix.double[]getElements()Returns all matrix elements in a flat, row-major (column indices vary fastest) array.intgetNumCol()Returns the number of columns in this matrix, which is always 2 in this implementation.intgetNumRow()Returns the number of rows in this matrix, which is always 2 in this implementation.inthashCode()Returns a hash code value based on the data values in this object.booleanisAffine()Returnstrueif this matrix represents an affine transform.booleanisIdentity()Returnstrueif this matrix is an identity matrix.voidnormalizeColumns()Normalizes all columns in-place.voidsetElement(int row, int column, double value)Modifies the value at the specified row and column of this matrix.voidsetElements(double[] elements)Sets all matrix elements from a flat, row-major (column indices vary fastest) array.voidtranspose()Sets the value of this matrix to its transpose.-
Methods inherited from class MatrixSIS
clone, convertAfter, convertBefore, equals, equals, getNumber, inverse, multiply, multiply, removeColumns, removeRows, setMatrix, setNumber, solve, toString, translate
-
-
-
-
Field Detail
-
SIZE
public static final int SIZE
The matrix size, which is 2.- See Also:
- Constant Field Values
-
m00
public double m00
The first matrix element in the first row.
-
m01
public double m01
The second matrix element in the first row.
-
m10
public double m10
The first matrix element in the second row.
-
m11
public double m11
The second matrix element in the second row.
-
-
Constructor Detail
-
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.- Parameters:
m00- the first matrix element in the first row.m01- the second matrix element in the first row.m10- the first matrix element in the second row.m11- the second matrix element in the second row.
-
Matrix2
public Matrix2(double[] elements) throws IllegalArgumentExceptionCreates a new matrix initialized to the specified values. The length of the given array must be 4 and the values in the same order than the above constructor.- Parameters:
elements- elements of the matrix. Column indices vary fastest.- Throws:
IllegalArgumentException- if the given array does not have the expected length.- See Also:
setElements(double[]),Matrices.create(int, int, double[])
-
-
Method Detail
-
castOrCopy
public static Matrix2 castOrCopy(Matrix matrix) throws MismatchedMatrixSizeException
Casts or copies the given matrix to aMatrix2implementation. If the givenmatrixis already an instance ofMatrix2, then it is returned unchanged. Otherwise this method verifies the matrix size, then copies all elements in a newMatrix2object.- Parameters:
matrix- the matrix to cast or copy, ornull.- Returns:
- the matrix argument if it can be safely casted (including
nullargument), or a copy of the given matrix otherwise. - Throws:
MismatchedMatrixSizeException- if the size of the given matrix is not 2×2.
-
getNumRow
public final int getNumRow()
Returns the number of rows in this matrix, which is always 2 in this implementation.- Returns:
- always 2.
-
getNumCol
public final int getNumCol()
Returns the number of columns in this matrix, which is always 2 in this implementation.- Returns:
- always 2.
-
getElement
public final double getElement(int row, int column)Retrieves the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance ofMatrix2, then them00…m11fields can be read directly for efficiency.- Specified by:
getElementin interfaceMatrix- Specified by:
getElementin classMatrixSIS- Parameters:
row- the row index, which can only be 0 or 1.column- the column index, which can only be 0 or 1.- Returns:
- the current value at the given row and column.
-
setElement
public final void setElement(int row, int column, double value)Modifies the value at the specified row and column of this matrix. This method can be invoked when the matrix size or type is unknown. If the matrix is known to be an instance ofMatrix2, then them00…m11fields can be set directly for efficiency.- Parameters:
row- the row index, which can only be 0 or 1.column- the column index, which can only be 0 or 1.value- the new value to set at the given row and column.
-
getElements
public final double[] getElements()
Returns all matrix elements in a flat, row-major (column indices vary fastest) array. The array length is 4.- Overrides:
getElementsin classMatrixSIS- Returns:
- a copy of all current matrix elements in a row-major array.
-
setElements
public final void setElements(double[] elements)
Sets all matrix elements from a flat, row-major (column indices vary fastest) array. The array length shall be 4.- Specified by:
setElementsin classMatrixSIS- Parameters:
elements- The new matrix elements in a row-major array.- See Also:
Matrices.create(int, int, double[])
-
isAffine
public final boolean isAffine()
Returnstrueif this matrix represents an affine transform. A transform is affine if the matrix is square and its last row contains only zeros, except in the last column which contains 1.- Overrides:
isAffinein classMatrixSIS- Returns:
trueif this matrix represents an affine transform.- See Also:
Matrices.isAffine(Matrix),LinearTransform.isAffine()
-
isIdentity
public final boolean isIdentity()
Returnstrueif this matrix is an identity matrix. This method is equivalent to the following code, except that it is potentially more efficient:return Matrices.isIdentity(this, 0.0);
- Specified by:
isIdentityin interfaceMatrix- Specified by:
isIdentityin classMatrixSIS- Returns:
trueif this matrix is an identity matrix.- See Also:
Matrices.isIdentity(Matrix, double),AffineTransform.isIdentity()
-
transpose
public void transpose()
Sets the value of this matrix to its transpose.- Specified by:
transposein classMatrixSIS
-
normalizeColumns
public void normalizeColumns()
Normalizes all columns in-place. Each columns in this matrix is considered as a vector. For each column (vector), this method computes the magnitude (vector length) as the square root of the sum of all square values. Then, all values in the column are divided by that magnitude.This method is useful when the matrix is a transform derivative. In such matrix, each column is a vector representing the displacement in target space when an coordinate in the source space is increased by one. Invoking this method turns those vectors into unitary vectors, which is useful for forming the basis of a new coordinate system.
- Overrides:
normalizeColumnsin classMatrixSIS
-
equals
public boolean equals(Object object)
Returnstrueif the specified object is of typeMatrix2and all of the data members are equal to the corresponding data members in this matrix.- Specified by:
equalsin interfaceLenientComparable- Overrides:
equalsin classMatrixSIS- Parameters:
object- the object to compare with this matrix for equality.- Returns:
trueif the given object is equal to this matrix.- See Also:
ComparisonMode.STRICT
-
hashCode
public int hashCode()
Returns a hash code value based on the data values in this object.- Overrides:
hashCodein classMatrixSIS- Returns:
- a hash code value for this matrix.
-
-