Package com.j3d.engine.math.matrix
Class Matrix3
java.lang.Object
com.j3d.engine.math.matrix.Matrix3
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionfinal double[][]The internal 2D array storing the matrix data. -
Constructor Summary
ConstructorsConstructorDescriptionMatrix3(double[][] data) Constructs aMatrix3by wrapping the given 2D array. -
Method Summary
Modifier and TypeMethodDescriptionintcols()Returns the number of columns in the matrix.copy()Creates a deep copy of this matrix.double[][]get()Returns the underlying 2D array that represents the matrix data.doubleget(int row, int col) Retrieves the value of a specific element in the matrix.static Matrix3identity()Creates a 3x3 identity matrix.static Matrix3Creates aMatrix3from anyMatrixInterfaceimplementation.introws()Returns the number of rows in the matrix.Transforms aVector3by this matrix.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.j3d.engine.math.matrix.MatrixInterface
toMatrixString
-
Field Details
-
data
public final double[][] dataThe 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 aMatrix3by wrapping the given 2D array.- Parameters:
data- A 3x3 2D double array. The constructor assumes the array is correctly sized.
-
-
Method Details
-
identity
Creates a 3x3 identity matrix.- Returns:
- A new
Matrix3instance representing the identity matrix.
-
of
Creates aMatrix3from anyMatrixInterfaceimplementation.- Parameters:
m- The matrix to convert.- Returns:
- A new
Matrix3instance with the same data. - Throws:
RuntimeException- if the input matrix is not 3x3.
-
transform
Transforms aVector3by this matrix.- Parameters:
v- The vector to be transformed.- Returns:
- A new
Vector3representing the result of the multiplication.
-
rows
public int rows()Description copied from interface:MatrixInterfaceReturns the number of rows in the matrix.- Specified by:
rowsin interfaceMatrixInterface- Returns:
- The number of rows.
-
cols
public int cols()Description copied from interface:MatrixInterfaceReturns the number of columns in the matrix.- Specified by:
colsin interfaceMatrixInterface- Returns:
- The number of columns.
-
get
public double get(int row, int col) Description copied from interface:MatrixInterfaceRetrieves the value of a specific element in the matrix.- Specified by:
getin interfaceMatrixInterface- 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:MatrixInterfaceReturns the underlying 2D array that represents the matrix data.- Specified by:
getin interfaceMatrixInterface- Returns:
- A 2D double array containing the matrix values.
-
copy
Creates a deep copy of this matrix.- Specified by:
copyin interfaceMatrixInterface- Returns:
- A new
Matrix3instance with the same values.
-