Package com.simsilica.mathd
Class Matrix3d
java.lang.Object
com.simsilica.mathd.Matrix3d
- All Implemented Interfaces:
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
Modifier and TypeFieldDescriptionprotected 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
-
Method Summary
Modifier and TypeMethodDescriptionclone()
Creates a copy of the current instance.double
Returns the determinant.boolean
Tests for exact equality with the argument, distinguishing -0 from 0.int
hashCode()
Returns a hash code.invert()
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.toString()
Returns a string representation of the matrix, which is unaffected.Returns the transpose.
-
Field Details
-
m00
protected double m00The element in row 0, column 0. -
m01
protected double m01The element in row 0, column 1. -
m02
protected double m02The element in row 0, column 2. -
m10
protected double m10The element in row 1, column 0. -
m11
protected double m11The element in row 1, column 1. -
m12
protected double m12The element in row 1, column 2. -
m20
protected double m20The element in row 2, column 0. -
m21
protected double m21The element in row 2, column 1. -
m22
protected double m22The 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 0m01
- the desired value for row 0, column 1m02
- the desired value for row 0, column 2m10
- the desired value for row 1, column 0m11
- the desired value for row 1, column 1m12
- the desired value for row 1, column 2m20
- the desired value for row 2, column 0m21
- the desired value for row 2, column 1m22
- the desired value for row 2, column 2
-
-
Method Details
-
clone
Creates a copy of the current instance. -
set
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
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
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
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
Returns the transpose. The current instance is unaffected.- Returns:
- a new Matrix3d
-
equals
Tests for exact equality with the argument, distinguishing -0 from 0. Ifo
is null, false is returned. Either way, the current instance is unaffected. -
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. -
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}]
-