public class GeneralMatrix extends Object implements XMatrix, Serializable
AffineTransform
,
Serialized FormConstructor and Description |
---|
GeneralMatrix(AffineTransform transform)
Constructs a 3×3 matrix from the specified affine transform.
|
GeneralMatrix(AxisDirection[] srcAxis,
AxisDirection[] dstAxis)
Constructs a transform changing axis order and/or direction.
|
GeneralMatrix(double[][] matrix)
Constructs a new matrix from a two-dimensional array of doubles.
|
GeneralMatrix(Envelope srcRegion,
AxisDirection[] srcAxis,
Envelope dstRegion,
AxisDirection[] dstAxis)
Constructs a transform mapping a source region to a destination region.
|
GeneralMatrix(Envelope srcRegion,
Envelope dstRegion)
Constructs a transform that maps a source region to a destination region.
|
GeneralMatrix(GeneralMatrix matrix)
Constructs a new matrix and copies the initial values from the parameter matrix.
|
GeneralMatrix(int size)
Constructs a square identity matrix of size
size × size . |
GeneralMatrix(int numRow,
int numCol)
Creates a matrix of size
numRow × numCol . |
GeneralMatrix(int numRow,
int numCol,
double... matrix)
Constructs a
numRow × numCol matrix initialized to the values
in the matrix array. |
GeneralMatrix(int numRow,
int numCol,
Matrix matrix)
Constructs a
numRow × numCol matrix initialized to the values
in the matrix array. |
GeneralMatrix(Matrix matrix)
Constructs a new matrix and copies the initial values from the parameter matrix.
|
Modifier and Type | Method and Description |
---|---|
void |
add(double scalar)
Performs an in-place scalar addition.
|
void |
add(double scalar,
XMatrix matrix)
Set to the scalar addition of
scalar+matrix |
void |
add(XMatrix matrix)
Set to the matrix addition of
this+matrix . |
void |
add(XMatrix matrix1,
XMatrix matrix2)
Set to the matrix addition of
matrix1+matrix2 . |
GeneralMatrix |
clone()
Returns a clone of this matrix.
|
void |
copySubMatrix(int rowSource,
int colSource,
int numRows,
int numCol,
int rowDest,
int colDest,
GeneralMatrix target)
Extract a subMatrix to the provided target
|
double |
determinate()
Computes the determinant
|
boolean |
equals(Matrix matrix,
double tolerance)
Compares the element values.
|
boolean |
equals(Object obj) |
void |
getColumn(int col,
double[] array)
Extract col to provided array.
|
double |
getElement(int row,
int column)
Returns the value at the row, column position in the matrix.
|
double[][] |
getElements()
Retrieves the specifiable values in the transformation matrix into a 2-dimensional array of
double precision values.
|
static double[][] |
getElements(Matrix matrix)
Retrieves the specifiable values in the transformation matrix into a 2-dimensional array of
double precision values.
|
int |
getNumCol()
Gets the number of columns in the matrix.
|
int |
getNumRow()
Gets the number of rows in the matrix.
|
void |
getRow(int row,
double[] array)
Extract row to provided array
|
int |
hashCode() |
void |
invert()
Inverts this matrix in place.
|
void |
invert(Matrix matrix)
Set to the inverse of the provided matrix.
|
boolean |
isAffine()
Returns
true if this matrix is an affine transform. |
boolean |
isIdentity()
Returns
true if this matrix is an identity matrix. |
boolean |
isIdentity(double tolerance)
Returns
true if this matrix is an identity matrix using the provided tolerance. |
static GeneralMatrix |
load(BufferedReader in,
Locale locale)
Loads data from the specified streal until the first blank line or end of stream.
|
static GeneralMatrix |
load(File file)
Loads data from the specified file until the first blank line or end of file.
|
void |
mul(double scalar)
Sets this matrix to the result of multiplying itself with the provided scalar.
|
void |
mul(double scalar,
Matrix matrix)
Sets the value of this matrix to the result of multiplying the provided scalar and matrix.
|
void |
mul(Matrix matrix)
In-place multiply with provided matrix.
|
void |
mul(Matrix matrix1,
Matrix matrix2)
In-place update from matrix1 * matrix2.
|
void |
multiply(Matrix matrix)
Sets the value of this matrix to the result of multiplying itself with the specified matrix.
|
void |
negate()
Changes the sign of each element in the matrix.
|
void |
negate(Matrix matrix)
Negates the value of this matrix:
this = -matrix . |
void |
set(double[] matrix)
Update in place to the provided matrix (row-order).
|
void |
setColumn(int column,
double... values)
Sets the value of the column using an array of values.
|
void |
setElement(int row,
int column,
double value)
Sets the value of the row, column position in the matrix.
|
void |
setIdentity()
Sets the main diagonal of this matrix to be 1.0.
|
void |
setRow(int row,
double... values)
Sets the value of the row using an array of values.
|
void |
setSize(int numRows,
int numCols)
Resize the matrix to the specified number of rows and columns (preserving remaining
elements).
|
void |
setZero()
Sets each value of the matrix to 0.0.
|
void |
sub(double scalar)
In-place matrix subtraction:
this - scalar . |
void |
sub(double scalar,
Matrix matrix)
Set to the difference of
scalar - matrix2 . |
void |
sub(Matrix matrix)
In-place matrix subtraction:
this - matrix . |
void |
sub(Matrix matrix1,
Matrix matrix2)
Set to the difference of
matrix1 - matrix2 . |
AffineTransform |
toAffineTransform2D()
Returns an affine transform for this matrix.
|
String |
toString()
Returns a string representation of this matrix.
|
void |
transpose()
Transposes the matrix.
|
void |
transpose(Matrix matrix)
Set to the transpose of the provided matrix.
|
public GeneralMatrix(int size)
size
× size
.size
- The number of rows and columns.public GeneralMatrix(int numRow, int numCol)
numRow
× numCol
. Elements on the
diagonal j==i are set to 1.numRow
- Number of rows.numCol
- Number of columns.public GeneralMatrix(int numRow, int numCol, double... matrix)
numRow
× numCol
matrix initialized to the values
in the matrix
array. The array values are copied in one row at a time in row major
fashion. The array should be exactly numRow*numCol
in length. Note that because
row and column numbering begins with zero, numRow
and numCol
will be one
larger than the maximum possible matrix index values.numRow
- Number of rows.numCol
- Number of columns.matrix
- Initial values in row orderpublic GeneralMatrix(int numRow, int numCol, Matrix matrix)
numRow
× numCol
matrix initialized to the values
in the matrix
array. The array values are copied in one row at a time in row major
fashion. The array should be exactly numRow*numCol
in length. Note that because
row and column numbering begins with zero, numRow
and numCol
will be one
larger than the maximum possible matrix index values.numRow
- Number of rows.numCol
- Number of columns.matrix
- Initial values in row orderpublic GeneralMatrix(double[][] matrix) throws IllegalArgumentException
matrix
- Array of rows. Each row must have the same length.IllegalArgumentException
- if the specified matrix is not regular (i.e. if all rows
doesn't have the same length).public GeneralMatrix(Matrix matrix)
matrix
- The matrix to copy.public GeneralMatrix(GeneralMatrix matrix)
matrix
- The matrix to copy.public GeneralMatrix(AffineTransform transform)
transform
- The matrix to copy.public GeneralMatrix(Envelope srcRegion, Envelope dstRegion)
If the source dimension is equals to the destination dimension, then the transform is affine. However, the following special cases are also handled:
srcRegion
- The source region.dstRegion
- The destination region.public GeneralMatrix(AxisDirection[] srcAxis, AxisDirection[] dstAxis)
If the source dimension is equals to the destination dimension, then the transform is
affine. However, the following special cases are also handled:
srcAxis
- The set of axis direction for source coordinate system.dstAxis
- The set of axis direction for destination coordinate system.IllegalArgumentException
- If dstAxis
contains some axis not found in srcAxis
, or if some colinear axis were found.public GeneralMatrix(Envelope srcRegion, AxisDirection[] srcAxis, Envelope dstRegion, AxisDirection[] dstAxis)
If the source dimension is equals to the destination dimension, then the transform is
affine. However, the following special cases are also handled:
srcRegion
- The source region.srcAxis
- Axis direction for each dimension of the source region.dstRegion
- The destination region.dstAxis
- Axis direction for each dimension of the destination region.MismatchedDimensionException
- if the envelope dimension doesn't matches the axis
direction array length.IllegalArgumentException
- If dstAxis
contains some axis not found in srcAxis
, or if some colinear axis were found.public static double[][] getElements(Matrix matrix)
matrix
- The matrix to extract elements from.public final double[][] getElements()
public final boolean isAffine()
true
if 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.public void negate()
public void negate(Matrix matrix)
XMatrix
this = -matrix
.public void transpose()
public void transpose(Matrix matrix)
XMatrix
public void invert()
XMatrix
public void invert(Matrix matrix) throws SingularMatrixException
XMatrix
invert
in interface XMatrix
matrix
- The matrix that is to be inverted. Not modified.SingularMatrixException
- if this matrix is not invertible.public int getNumRow()
public int getNumCol()
public double getElement(int row, int column)
getElement
in interface XMatrix
getElement
in interface Matrix
row
- column
- public void setColumn(int column, double... values)
XMatrix
public void setRow(int row, double... values)
XMatrix
public void setElement(int row, int column, double value)
setElement
in interface Matrix
row
- column
- value
- public void setZero()
public void setIdentity()
setIdentity
in interface XMatrix
public final boolean isIdentity()
true
if this matrix is an identity matrix.isIdentity
in interface Matrix
true
if this matrix is an identity matrix.public final boolean isIdentity(double tolerance)
true
if 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 returning true
if and only if all differences are smaller than
or equal to tolerance
.isIdentity
in interface XMatrix
tolerance
- The tolerance value.true
if this matrix is close enough to the identity matrix given the
tolerance value.public final void multiply(Matrix matrix)
this
= this
× matrix
. In the context
of coordinate transformations, this is equivalent to
AffineTransform.concatenate
:
first transforms by the supplied transform and then transform the result by the original
transform.public boolean equals(Matrix matrix, double tolerance)
XMatrix
public final AffineTransform toAffineTransform2D() throws IllegalStateException
IllegalStateException
- if this matrix is not 3×3, or if the last row is not
[0 0 1]
.public static GeneralMatrix load(File file) throws IOException
file
- The file to read.IOException
- if an error occured while reading the file.public static GeneralMatrix load(BufferedReader in, Locale locale) throws IOException
in
- The stream to read.locale
- The locale for the numbers to be parsed.IOException
- if an error occured while reading the stream.public String toString()
public GeneralMatrix clone()
clone
in interface Matrix
clone
in class Object
Object.clone()
public void copySubMatrix(int rowSource, int colSource, int numRows, int numCol, int rowDest, int colDest, GeneralMatrix target)
public void getColumn(int col, double[] array)
public void mul(double scalar)
XMatrix
public void mul(double scalar, Matrix matrix)
XMatrix
public void getRow(int row, double[] array)
public final void mul(Matrix matrix)
public void sub(double scalar)
XMatrix
this - scalar
.public void sub(double scalar, Matrix matrix)
XMatrix
scalar - matrix2
.public void sub(Matrix matrix)
XMatrix
this - matrix
.public void sub(Matrix matrix1, Matrix matrix2)
XMatrix
matrix1 - matrix2
.public void set(double[] matrix)
matrix
- public void setSize(int numRows, int numCols)
numRows
- The new number of rows in the matrix.numCols
- The new number of columns in the matrix.public void add(double scalar)
XMatrix
public void add(double scalar, XMatrix matrix)
XMatrix
scalar+matrix
public void add(XMatrix matrix)
XMatrix
this+matrix
.public void add(XMatrix matrix1, XMatrix matrix2)
XMatrix
matrix1+matrix2
.public double determinate()
XMatrix
determinate
in interface XMatrix
Copyright © 1996–2019 Geotools. All rights reserved.