public abstract class MatrixSIS extends Object implements Matrix, LenientComparable, Cloneable, Serializable
Matrix
able to perform some operations of interest to Spatial Information Systems (SIS).
This class completes the GeoAPI Matrix
interface with some operations used by sis-referencing
.
It is not a MatrixSIS
goal to provide all possible Matrix operations, as there is too many of them.
This class focuses only on:
transpose()
, inverse()
, multiply(Matrix)
;isAffine()
, normalizeColumns()
.Defined in the sis-referencing
module
Modifier | Constructor and Description |
---|---|
protected |
MatrixSIS()
For sub-class constructors.
|
Modifier and Type | Method and Description |
---|---|
static MatrixSIS |
castOrCopy(Matrix matrix)
Casts or copies the given matrix to a SIS implementation.
|
MatrixSIS |
clone()
Returns a clone of this matrix.
|
boolean |
equals(Matrix matrix,
double tolerance)
Compares the given matrices for equality, using the given absolute tolerance threshold.
|
boolean |
equals(Object object,
ComparisonMode mode)
Compares this matrix with the given object for equality.
|
abstract double |
getElement(int row,
int column)
Retrieves the value at the specified row and column of this matrix.
|
abstract double[] |
getElements()
Returns a copy of all matrix elements in a flat, row-major (column indices vary fastest) array.
|
Number |
getNumber(int row,
int column)
Retrieves the value at the specified row and column of this matrix, wrapped in a
Number . |
MatrixSIS |
inverse()
Returns the inverse of this matrix.
|
abstract boolean |
isAffine()
Returns
true if this matrix represents an affine transform. |
abstract boolean |
isIdentity()
Returns
true if this matrix is an identity matrix. |
MatrixSIS |
multiply(Matrix matrix)
Returns a new matrix which is the result of multiplying this matrix with the specified one.
|
abstract void |
normalizeColumns()
Normalizes all columns in-place.
|
abstract void |
setElements(double[] elements)
Sets all matrix elements from a flat, row-major (column indices vary fastest) array.
|
MatrixSIS |
solve(Matrix matrix)
Returns the value of U which solves
this × U = matrix . |
String |
toString()
Returns a unlocalized string representation of this matrix.
|
abstract void |
transpose()
Sets the value of this matrix to its transpose.
|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getNumCol, getNumRow, setElement
equals
public static MatrixSIS castOrCopy(Matrix matrix)
matrix
is already
an instance of MatrixSIS
, then it is returned unchanged. Otherwise all elements
are copied in a new MatrixSIS
object.matrix
- The matrix to cast or copy, or null
.null
argument),
or a copy of the given matrix otherwise.Matrices.copy(Matrix)
public Number getNumber(int row, int column)
Number
.
The Number
type depends on the matrix accuracy.row
- The row index, from 0 inclusive to Matrix.getNumRow()
exclusive.column
- The column index, from 0 inclusive to Matrix.getNumCol()
exclusive.public abstract double getElement(int row, int column)
getElement
in interface Matrix
row
- The row index, from 0 inclusive to Matrix.getNumRow()
exclusive.column
- The column index, from 0 inclusive to Matrix.getNumCol()
exclusive.public abstract double[] getElements()
Matrix.getNumRow() * Matrix.getNumCol()
.public abstract void setElements(double[] elements)
Matrix.getNumRow() * Matrix.getNumCol()
.elements
- The new matrix elements in a row-major array.IllegalArgumentException
- If the given array does not have the expected length.Matrices.create(int, int, double[])
public abstract boolean isAffine()
true
if 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.true
if this matrix represents an affine transform.Matrices.isAffine(Matrix)
public abstract boolean isIdentity()
true
if 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);
isIdentity
in interface Matrix
true
if this matrix is an identity matrix.Matrices.isIdentity(Matrix, double)
,
AffineTransform.isIdentity()
public abstract void transpose()
public abstract void normalizeColumns()
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 ordinate 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.
public MatrixSIS multiply(Matrix matrix) throws MismatchedMatrixSizeException
this
× matrix
.
Matrix.multiply(other)
is equivalent to
AffineTransform.concatenate(other)
:
first transforms by the supplied transform and then transform the result by the original transform.matrix
- The matrix to multiply to this matrix.this
× matrix
.MismatchedMatrixSizeException
- if the number of rows in the given matrix is not equals to the
number of columns in this matrix.public MatrixSIS solve(Matrix matrix) throws MismatchedMatrixSizeException, NoninvertibleMatrixException
this
× U = matrix
.
This is equivalent to first computing the inverse of this
, then multiplying the result
by the given matrix.matrix
- The matrix to solve.this
× U = matrix
.MismatchedMatrixSizeException
- if the number of rows in the given matrix is not equals
to the number of columns in this matrix.NoninvertibleMatrixException
- if this matrix is not invertible.public MatrixSIS inverse() throws NoninvertibleMatrixException
NoninvertibleMatrixException
- if this matrix is not invertible.AffineTransform.createInverse()
public boolean equals(Matrix matrix, double tolerance)
The matrix elements are compared as below:
Double.NaN
values are considered equals to all other NaN values.matrix
- The matrix to compare.tolerance
- The tolerance value.true
if this matrix is close enough to the given matrix given the tolerance value.Matrices.equals(Matrix, Matrix, double, boolean)
public boolean equals(Object object, 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
:
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).IGNORE_METADATA
: same as BY_CONTRACT
.
APPROXIMATIVE
:
the two matrices 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 any future SIS versions.equals
in interface LenientComparable
object
- The object to compare to this
.mode
- The strictness level of the comparison.true
if both objects are equal.Matrices.equals(Matrix, Matrix, ComparisonMode)
public MatrixSIS clone()
clone
in interface Matrix
clone
in class Object
Matrices.copy(Matrix)
public String toString()
toString
in class Object
Matrices.toString(Matrix)
Copyright © 2010–2015 The Apache Software Foundation. All rights reserved.