Class Matrix3d

java.lang.Object
com.simsilica.mathd.Matrix3d
All Implemented Interfaces:
Cloneable

public class Matrix3d extends Object implements Cloneable
A square matrix composed of 9 double-precision elements, used to represent linear transformations of 3-dimensional vectors.

Methods with names ending in "Local" modify the current instance. They are used to avoid creating temporary objects.

By convention, indices start from zero. The conventional order of indices is (row, column).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double
    The element in row 0, column 0.
    protected double
    The element in row 0, column 1.
    protected double
    The element in row 0, column 2.
    protected double
    The element in row 1, column 0.
    protected double
    The element in row 1, column 1.
    protected double
    The element in row 1, column 2.
    protected double
    The element in row 2, column 0.
    protected double
    The element in row 2, column 1.
    protected double
    The element in row 2, column 2.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates an identity matrix (diagonals = 1, other elements = 0).
    Matrix3d(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
    Instantiates a matrix with the specified elements.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a copy of the current instance.
    double
    Returns the determinant.
    boolean
    Tests for exact equality with the argument, distinguishing -0 from 0.
    int
    Returns a hash code.
    Returns the multiplicative inverse.
    boolean
    Tests for identity.
    Configures the matrix as an identity matrix (diagonals = 1, other elements = 0).
    multLocal(double scale)
    Multiplies by the scalar argument and returns the (modified) current instance.
    Copies all elements of the argument to the current instance.
    Returns a string representation of the matrix, which is unaffected.
    Returns the transpose.

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • m00

      protected double m00
      The element in row 0, column 0.
    • m01

      protected double m01
      The element in row 0, column 1.
    • m02

      protected double m02
      The element in row 0, column 2.
    • m10

      protected double m10
      The element in row 1, column 0.
    • m11

      protected double m11
      The element in row 1, column 1.
    • m12

      protected double m12
      The element in row 1, column 2.
    • m20

      protected double m20
      The element in row 2, column 0.
    • m21

      protected double m21
      The element in row 2, column 1.
    • m22

      protected double m22
      The element in row 2, column 2.
  • Constructor Details

    • Matrix3d

      public Matrix3d()
      Instantiates an identity matrix (diagonals = 1, other elements = 0).
    • Matrix3d

      public Matrix3d(double m00, double m01, double m02, double m10, double m11, double m12, double m20, double m21, double m22)
      Instantiates a matrix with the specified elements.
      Parameters:
      m00 - the desired value for row 0, column 0
      m01 - the desired value for row 0, column 1
      m02 - the desired value for row 0, column 2
      m10 - the desired value for row 1, column 0
      m11 - the desired value for row 1, column 1
      m12 - the desired value for row 1, column 2
      m20 - the desired value for row 2, column 0
      m21 - the desired value for row 2, column 1
      m22 - the desired value for row 2, column 2
  • Method Details

    • clone

      public Matrix3d clone()
      Creates a copy of the current instance.
      Overrides:
      clone in class Object
      Returns:
      a new instance, equivalent to this one
    • set

      public Matrix3d set(Matrix3d mat)
      Copies all elements of the argument to the current instance.
      Parameters:
      mat - the desired value (not null, unaffected)
      Returns:
      the (modified) current instance (for chaining)
    • makeIdentity

      public Matrix3d makeIdentity()
      Configures the matrix as an identity matrix (diagonals = 1, other elements = 0).
      Returns:
      the (modified) current instance (for chaining)
    • isIdentity

      public boolean isIdentity()
      Tests for identity. The matrix is unaffected.
      Returns:
      true if all diagonal elements are 1 and all other elements are 0 or -0, otherwise false
    • multLocal

      public Matrix3d multLocal(double scale)
      Multiplies by the scalar argument and returns the (modified) current instance.
      Parameters:
      scale - the scaling factor
      Returns:
      the (modified) current instance (for chaining)
    • determinant

      public double determinant()
      Returns the determinant. The matrix is unaffected.
      Returns:
      the determinant
    • invert

      public Matrix3d invert()
      Returns the multiplicative inverse. If the current instance is singular, an identity matrix is returned. The current instance is unaffected.
      Returns:
      a new Matrix3d
    • transpose

      public Matrix3d transpose()
      Returns the transpose. The current instance is unaffected.
      Returns:
      a new Matrix3d
    • equals

      public boolean equals(Object o)
      Tests for exact equality with the argument, distinguishing -0 from 0. If o is null, false is returned. Either way, the current instance is unaffected.
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare (may be null, unaffected)
      Returns:
      true if this and o have identical values, otherwise false
    • hashCode

      public int hashCode()
      Returns a hash code. If two matrices have identical values, they will have the same hash code. The matrix is unaffected.
      Overrides:
      hashCode in class Object
      Returns:
      a 32-bit value for use in hashing
    • toString

      public String toString()
      Returns a string representation of the matrix, which is unaffected. For example, an identity matrix would be represented by:
       Matrix3d[{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}]
       
      Overrides:
      toString in class Object
      Returns:
      a descriptive string of text (not null, not empty)