Package org.apache.sis.referencing.operation.matrix

# Class Matrix3

Object
MatrixSIS
Matrix3

All Implemented Interfaces:
  `Serializable`, `Cloneable`, `LenientComparable`, `Matrix`

public class Matrix3 extends MatrixSIS
A matrix of fixed 3×3 size. The matrix members are:

>      ┌             ┐
>      │ m00 m01 m02 │
>      │ m10 m11 m12 │
>      │ m20 m21 m22 │
>      └             ┘

Since:
  0.4
See Also:
  - `Matrix1`
  - `Matrix2`
  - `Matrix4`
  - Serialized Form

Defined in the `sis-referencing` module

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `double`
  `m00`
  The first matrix element in the first row.
  `double`
  `m01`
  The second matrix element in the first row.
  `double`
  `m02`
  The third matrix element in the first row.
  `double`
  `m10`
  The first matrix element in the second row.
  `double`
  `m11`
  The second matrix element in the second row.
  `double`
  `m12`
  The third matrix element in the second row.
  `double`
  `m20`
  The first matrix element in the third row.
  `double`
  `m21`
  The second matrix element in the third row.
  `double`
  `m22`
  The third matrix element in the third row.
  `static final int`
  `SIZE`
  The matrix size, which is 3.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Matrix3()`
  Creates a new identity matrix.
  `Matrix3(double[] elements)`
  Creates a new matrix initialized to the specified values.
  `Matrix3(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)`
  Creates a new matrix initialized to the specified values.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static Matrix3`
  `castOrCopy(Matrix matrix)`
  Casts or copies the given matrix to a `Matrix3` implementation.
  `Matrix3`
  `clone()`
  Returns a clone of this matrix.
  `final double`
  `getElement(int row, int column)`
  Retrieves the value at the specified row and column of this matrix.
  `final double[]`
  `getElements()`
  Returns all matrix elements in a flat, row-major (column indices vary fastest) array.
  `final int`
  `getNumCol()`
  Returns the number of columns in this matrix, which is always 3 in this implementation.
  `final int`
  `getNumRow()`
  Returns the number of rows in this matrix, which is always 3 in this implementation.
  `final boolean`
  `isAffine()`
  Returns `true` if this matrix represents an affine transform.
  `final boolean`
  `isIdentity()`
  Returns `true` if this matrix is an identity matrix.
  `final void`
  `setElement(int row, int column, double value)`
  Modifies the value at the specified row and column of this matrix.
  `final void`
  `setElements(double[] elements)`
  Sets all matrix elements from a flat, row-major (column indices vary fastest) array.
  `void`
  `transpose()`
  Sets the value of this matrix to its transpose.

  ### Methods inherited from class MatrixSIS

  `convertAfter, convertBefore, equals, equals, equals, getNumber, hashCode, inverse, multiply, multiply, normalizeColumns, removeColumns, removeRows, setMatrix, setNumber, solve, toString, translate`

  ### Methods inherited from class Object

  `finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### SIZE

    public static final int SIZE
    The matrix size, which is 3.
    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.

  - ### m02

    public double m02
    The third 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.

  - ### m12

    public double m12
    The third matrix element in the second row.

  - ### m20

    public double m20
    The first matrix element in the third row.

  - ### m21

    public double m21
    The second matrix element in the third row.

  - ### m22

    public double m22
    The third matrix element in the third row.

- ## Constructor Details

  - ### Matrix3

    public Matrix3()
    Creates a new identity matrix.

  - ### Matrix3

    public Matrix3(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
    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.
      `m02` - the third matrix element in the first row.
      `m10` - the first matrix element in the second row.
      `m11` - the second matrix element in the second row.
      `m12` - the third matrix element in the second row.
      `m20` - the first matrix element in the third row.
      `m21` - the second matrix element in the third row.
      `m22` - the third matrix element in the third row.

  - ### Matrix3

    public Matrix3(double[] elements) throws IllegalArgumentException
    Creates a new matrix initialized to the specified values. The length of the given array must be 9 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 Details

  - ### castOrCopy

    public static Matrix3 castOrCopy(Matrix matrix) throws MismatchedMatrixSizeException
    Casts or copies the given matrix to a `Matrix3` implementation. If the given `matrix` is already an instance of `Matrix3`, then it is returned unchanged. Otherwise this method verifies the matrix size, then copies all elements in a new `Matrix3` object.
    Parameters:
      `matrix` - the matrix to cast or copy, or `null`.
    Returns:
      the matrix argument if it can be safely casted (including `null` argument), or a copy of the given matrix otherwise.
    Throws:
      `MismatchedMatrixSizeException` - if the size of the given matrix is not 3×3.

  - ### getNumRow

    public final int getNumRow()
    Returns the number of rows in this matrix, which is always 3 in this implementation.
    Returns:
      always 3.

  - ### getNumCol

    public final int getNumCol()
    Returns the number of columns in this matrix, which is always 3 in this implementation.
    Returns:
      always 3.

  - ### 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 of `Matrix3`, then the `m00` … `m22` fields can be read directly for efficiency.
    Specified by:
      `getElement` in interface `Matrix`
    Specified by:
      `getElement` in class `MatrixSIS`
    Parameters:
      `row` - the row index, from 0 inclusive to 3 exclusive.
      `column` - the column index, from 0 inclusive to 3 exclusive.
    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 of `Matrix3`, then the `m00` … `m22` fields can be set directly for efficiency.
    Parameters:
      `row` - the row index, from 0 inclusive to 3 exclusive.
      `column` - the column index, from 0 inclusive to 3 exclusive.
      `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 9.
    Overrides:
      `getElements` in class `MatrixSIS`
    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 9.
    Specified by:
      `setElements` in class `MatrixSIS`
    Parameters:
      `elements` - The new matrix elements in a row-major array.
    See Also:
      - `Matrices​.create(int, int, double[])`

  - ### isAffine

    public final boolean isAffine()
    Returns `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.
    Overrides:
      `isAffine` in class `MatrixSIS`
    Returns:
      `true` if this matrix represents an affine transform.
    See Also:
      - `Matrices​.isAffine(Matrix)`
      - `LinearTransform​.isAffine()`

  - ### isIdentity

    public final boolean isIdentity()
    Returns `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);

    Specified by:
      `isIdentity` in interface `Matrix`
    Specified by:
      `isIdentity` in class `MatrixSIS`
    Returns:
      `true` if 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:
      `transpose` in class `MatrixSIS`

  - ### clone

    public Matrix3 clone()
    Returns a clone of this matrix.
    Specified by:
      `clone` in interface `Matrix`
    Overrides:
      `clone` in class `MatrixSIS`
    Returns:
      a new matrix of the same class and with the same values than this matrix.
    See Also:
      - `Matrices​.copy(Matrix)`