|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectStatic
Matrices
public class Matrices
Static utility methods for creating and manipulating matrices. The factory methods select one of
the Matrix1, Matrix2, Matrix3, Matrix4 or GeneralMatrix
implementations according the desired matrix size. Note that if the matrix size is know at compile
time, it may be more efficient to invoke directly the constructor of the appropriate class instead.
| referencing/geotk-referencing (download) | View source code for this class |
| Method Summary | |
|---|---|
static XMatrix |
copy(Matrix matrix)
Creates a new matrix which is a copy of the specified matrix. |
static XMatrix |
create(int size)
Creates a square identity matrix of size size × size. |
static XMatrix |
create(int numRow,
int numCol)
Creates a matrix of size numRow × numCol. |
static XMatrix |
create(int numRow,
int numCol,
double[] elements)
Creates a matrix of size numRow × numCol
initialized to the given elements. |
static XMatrix |
createDimensionFilter(int sourceDim,
int[] toKeep)
Creates a matrix for an affine transform that keep only a subset of source ordinate values. |
static boolean |
equals(Matrix m1,
Matrix m2,
ComparisonMode mode)
Compares the given matrices for equality, using the given comparison strictness level. |
static boolean |
equals(Matrix m1,
Matrix m2,
double epsilon,
boolean relative)
Compares the given matrices for equality, using the given relative or absolute tolerance threshold. |
static void |
filterRoundingErrors(XMatrix matrix,
int scale,
double tolerance)
Rounds the coefficients that are relatively close to integers, given a threshold value. |
static Matrix |
getMatrix(MathTransform transform)
If the given transform is linear, returns its coefficients as a matrix. |
static Matrix |
invert(Matrix matrix)
Inverts the specified matrix, maybe (but not always) in place. |
static boolean |
isAffine(Matrix matrix)
Returns true if the given matrix is affine. |
static Matrix |
multiply(Matrix matrix1,
Matrix matrix2)
Computes matrix1 × matrix2, reusing one of the given matrices. |
static Matrix |
resizeAffine(Matrix matrix,
int sourceDimension,
int targetDimension)
Returns the given matrix resized to the given dimensions. |
static void |
reverseAxisDirection(Matrix matrix,
int dimension,
double span)
Modifies the given matrix in order to reverse the direction of the axis at the given dimension. |
static AffineTransform |
toAffineTransform(Matrix matrix)
Returns the given matrix as a Java2D affine transform. |
static GeneralMatrix |
toGeneralMatrix(Matrix matrix)
Converts the specified matrix to GeneralMatrix. |
static XMatrix |
toOptimalMatrix(Matrix matrix)
Converts the specified matrix to the most suitable Geotk implementation. |
static XMatrix |
toXMatrix(Matrix matrix)
Converts the specified matrix to a Geotk implementation. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static XMatrix create(int size)
size × size.
size - For an affine transform, this is the number of source and target dimensions + 1.
public static XMatrix create(int numRow,
int numCol)
numRow × numCol.
Elements on the diagonal (j == i) are set to 1.
numRow - For an affine transform, this is the number of target dimensions + 1.numCol - For an affine transform, this is the number of source dimensions + 1.
public static XMatrix create(int numRow,
int numCol,
double[] elements)
numRow × numCol
initialized to the given elements. The elements array size must be equals
to numRow*numCol. Column indices vary fastest, as expected by the
GeneralMatrix.GeneralMatrix(int,int,double[]) constructor.
numRow - Number of rows.numCol - Number of columns.elements - Elements of the matrix. Column indices vary fastest.
public static XMatrix createDimensionFilter(int sourceDim,
int[] toKeep)
throws IndexOutOfBoundsException
toKeep.length+1) × (sourceDim+1).
sourceDim - the dimension of source coordinates.toKeep - the indices of source ordinate values to keep.
IndexOutOfBoundsException - if a value of toKeep
is lower than 0 or not smaller than sourceDim.MathTransforms.dimensionFilter(int, int[])public static XMatrix copy(Matrix matrix)
matrix - The matrix to copy.
public static Matrix getMatrix(MathTransform transform)
LinearTransform, returns
LinearTransform.getMatrix().AffineTransform,
returns its coefficients in a Matrix3 instance.null.
transform - The transform, or null.
null if none.public static XMatrix toXMatrix(Matrix matrix)
matrix is already
an instance of XMatrix, then it is returned unchanged. Otherwise all elements
are copied in a new XMatrix object.
matrix - The matrix to convert, or null.
null argument),
or a copy of the given matrix otherwise.public static XMatrix toOptimalMatrix(Matrix matrix)
Matrix1, Matrix2,
Matrix3 or Matrix4 specialized classes, then it is returned unchanged.Matrix1, Matrix2,
Matrix3 or Matrix4 respectively, and the new instance is returned.toXMatrix(Matrix).Using those specialized implementations brings a little bit of performance and, more important, precision in the floating point results of matrix operations.
matrix - The matrix to convert, or null.
null argument),
or a copy of the given matrix otherwise.public static GeneralMatrix toGeneralMatrix(Matrix matrix)
GeneralMatrix. If matrix is already an
instance of GeneralMatrix, then it is returned unchanged. Otherwise all elements
are copied in a new GeneralMatrix object.
Consider using toXMatrix(Matrix) instead than this method if a XMatrix
instance is sufficient. Use this method only if a GeneralMatrix is really necessary.
matrix - The matrix to convert, or null.
null argument),
or a copy of the given matrix otherwise.
public static AffineTransform toAffineTransform(Matrix matrix)
throws IllegalArgumentException
matrix - The matrix to returns as an affine transform.
null argument),
or a copy of the given matrix otherwise.
IllegalArgumentException - if the given matrix size is not 3×3
or the matrix is not affine.Matrix3.toAffineTransform(),
GeneralMatrix.toAffineTransform2D()public static boolean isAffine(Matrix matrix)
true if the given matrix is affine.
matrix - The matrix to test.
true if the matrix is affine.XMatrix.isAffine()
public static Matrix resizeAffine(Matrix matrix,
int sourceDimension,
int targetDimension)
The caller should ensure that isAffine(Matrix) returns true before to invoke
this method, since this is not verified by this method.
matrix - The matrix to resize.sourceDimension - The desired number of source dimensions.targetDimension - The desired number of target dimensions.
matrix
argument itself if no resizing was needed.
public static void reverseAxisDirection(Matrix matrix,
int dimension,
double span)
matrix - The matrix to modify.dimension - The dimension of the axis to reverse.span - The envelope span at the dimension of the axis to be reversed,
in units of the source coordinate system.
public static Matrix multiply(Matrix matrix1,
Matrix matrix2)
matrix1 × matrix2, reusing one of the given matrices.
The two given matrices shall be considered invalid after this method call.
matrix1 - The first matrix to multiply. May be overwritten by the result.matrix2 - The second matrix to multiply. May be overwritten by the result.
public static Matrix invert(Matrix matrix)
throws NoninvertibleTransformException
SingularMatrixException), then the exception
is wrapped into a NoninvertibleTransformException.
This method performs a special check for non-square matrix in an attempt to invert them anyway. This is possible only if some columns or rows contain contains only 0 elements.
matrix - The matrix to invert.
matrix itself.
NoninvertibleTransformException - if the given matrix is not invertible.
public static void filterRoundingErrors(XMatrix matrix,
int scale,
double tolerance)
tolerance value by the given vector magnitude.adjusted = Math.round(element*scale)/scale.
In other words, the tolerance argument given to this method is the value that we
would use if we knew that the matrix was close to an identity matrix, without worrying
about the scale argument. This method will take care of adjusting the tolerance
threshold for the actual matrix values. However this algorithm is designed for matrix
representing affine transforms (not general matrix).
matrix - The matrix in which to filter rounding errors in-place.scale - A scale factor by which to multiply each element before to round the scaled value.
For example a value of 10 will allow this method to round 0.2000…1 as 0.2.tolerance - The relative tolerance threshold.
public static boolean equals(Matrix m1,
Matrix m2,
double epsilon,
boolean relative)
Double.NaN values are considered equals to all other NaN values
If relative is true, then for any pair of values v1j,i
and v2j,i to compare, the tolerance threshold is scaled by
max(abs(v1), abs(v2)). Otherwise the threshold is used as-is.
m1 - The first matrix to compare, or null.m2 - The second matrix to compare, or null.epsilon - The tolerance value.relative - If true, then the tolerance value is relative to the magnitude
of the matrix elements being compared.
true if the values of the two matrix do not differ by a quantity
greater than the given tolerance threshold.XMatrix.equals(Matrix, double)
public static boolean equals(Matrix m1,
Matrix m2,
ComparisonMode mode)
mode argument:
STRICT: the two matrices must be of the same
class, have the same size and the same element values.BY_CONTRACT/IGNORE_METADATA: the two matrices must have the same size and the same element
values, but are not required to be the same implementation class (any Matrix
is okay).APPROXIMATIVE: the two matrixes must have
the same size, but the element values can differ up to some threshold. The threshold
value is determined empirically and may change in future Geotk versions.
m1 - The first matrix to compare, or null.m2 - The second matrix to compare, or null.mode - The strictness level of the comparison.
true if both matrices are equal.XMatrix.equals(Object, ComparisonMode)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||