Package com.j3d.engine.math.matrix
Interface MatrixInterface
public interface MatrixInterface
Defines the core contract for a matrix implementation. This interface provides
methods for accessing dimensions, getting and setting individual elements,
retrieving the underlying data array, and creating a copy of the matrix.
It also includes a default method for generating a formatted string representation.
A huge thank you to Mindbourne for their AP Maths videos on matrices.
- Author:
- Lehlogonolo Poole
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionintcols()Returns the number of columns in the matrix.copy()Creates and returns 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.introws()Returns the number of rows in the matrix.default StringGenerates a formatted string representation of the matrix, suitable for console output.
-
Method Details
-
rows
int rows()Returns the number of rows in the matrix.- Returns:
- The number of rows.
-
cols
int cols()Returns the number of columns in the matrix.- Returns:
- The number of columns.
-
get
double get(int row, int col) Retrieves the value of a specific element in the matrix.- 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
double[][] get()Returns the underlying 2D array that represents the matrix data.- Returns:
- A 2D double array containing the matrix values.
-
copy
MatrixInterface copy()Creates and returns a deep copy of this matrix.- Returns:
- A new
MatrixInterfaceinstance with the same values as the original.
-
toMatrixString
Generates a formatted string representation of the matrix, suitable for console output. The matrix is enclosed in box-drawing characters, and columns are aligned for readability. Values are formatted to four decimal places.- Returns:
- A string representing the formatted matrix.
-