Class Matrix3

java.lang.Object
com.j3d.engine.math.matrix.Matrix3
All Implemented Interfaces:
MatrixInterface

public final class Matrix3 extends Object implements MatrixInterface
Represents a final, specialized 3x3 matrix.

This class provides a concrete and optimised implementation for a 3x3 matrix, commonly used for 2D transformations (in homogeneous coordinates) or 3D rotations. It implements the MatrixInterface and ensures that all instances are correctly sized.

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • data

      public final double[][] data
      The internal 2D array storing the matrix data. This field is final, but the array elements themselves can be modified.
  • Constructor Details

    • Matrix3

      public Matrix3(double[][] data)
      Constructs a Matrix3 by wrapping the given 2D array.
      Parameters:
      data - A 3x3 2D double array. The constructor assumes the array is correctly sized.
  • Method Details

    • identity

      public static Matrix3 identity()
      Creates a 3x3 identity matrix.
      Returns:
      A new Matrix3 instance representing the identity matrix.
    • of

      public static Matrix3 of(MatrixInterface m)
      Creates a Matrix3 from any MatrixInterface implementation.
      Parameters:
      m - The matrix to convert.
      Returns:
      A new Matrix3 instance with the same data.
      Throws:
      RuntimeException - if the input matrix is not 3x3.
    • transform

      public Vector3 transform(Vector3 v)
      Transforms a Vector3 by this matrix.
      Parameters:
      v - The vector to be transformed.
      Returns:
      A new Vector3 representing the result of the multiplication.
    • rows

      public int rows()
      Description copied from interface: MatrixInterface
      Returns the number of rows in the matrix.
      Specified by:
      rows in interface MatrixInterface
      Returns:
      The number of rows.
    • cols

      public int cols()
      Description copied from interface: MatrixInterface
      Returns the number of columns in the matrix.
      Specified by:
      cols in interface MatrixInterface
      Returns:
      The number of columns.
    • get

      public double get(int row, int col)
      Description copied from interface: MatrixInterface
      Retrieves the value of a specific element in the matrix.
      Specified by:
      get in interface MatrixInterface
      Parameters:
      row - The row index of the element (0-based).
      col - The column index of the element (0-based).
      Returns:
      The value at the specified position.
    • get

      public double[][] get()
      Description copied from interface: MatrixInterface
      Returns the underlying 2D array that represents the matrix data.
      Specified by:
      get in interface MatrixInterface
      Returns:
      A 2D double array containing the matrix values.
    • copy

      public MatrixInterface copy()
      Creates a deep copy of this matrix.
      Specified by:
      copy in interface MatrixInterface
      Returns:
      A new Matrix3 instance with the same values.