Package com.j3d.engine.math.matrix
Class MatrixMath
java.lang.Object
com.j3d.engine.math.matrix.MatrixMath
Provides a collection of static utility methods for performing mathematical operations
on matrices that implement the
MatrixInterface. This class includes methods
for matrix creation, validation, addition, subtraction, and multiplication.
This is an abstract utility class and cannot be instantiated.
- Author:
- Lehlogonolo Poole
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MatrixInterfaceadd(MatrixInterface m1, MatrixInterface m2) Performs element-wise addition of two matrices.static booleanChecks if two matrices have the same number of rows and columns.static MatrixInterfacematrixOf(double[][] m) Creates aMatrixInterfaceinstance from a 2D double array.static MatrixInterfacemult(MatrixInterface m1, MatrixInterface m2) Performs matrix multiplication (m1 * m2).static MatrixInterfacesub(MatrixInterface m1, MatrixInterface m2) Performs element-wise subtraction of two matrices (m1 - m2).protected static voidvalidate(double[][] m) Validates the structure of a 2D double array to ensure it can represent a valid matrix.
-
Constructor Details
-
MatrixMath
public MatrixMath()
-
-
Method Details
-
validate
protected static void validate(double[][] m) Validates the structure of a 2D double array to ensure it can represent a valid matrix. This method checks for three conditions:- The input is a 2D array.
- All rows have the same length.
- The array does not contain any
Double.NaNvalues.
- Parameters:
m- The 2D double array to validate.- Throws:
IllegalStateException- if the array is not a valid matrix structure.
-
matrixOf
Creates aMatrixInterfaceinstance from a 2D double array.This factory method serves as a bridge between raw
double[][]arrays and theMatrixInterfaceecosystem. It first validates the array to ensure it represents a well-formed matrix.Based on the dimensions of the input array, this method will return a specialized, high-performance implementation (e.g.,
Matrix3for 3x3) or a generic, anonymous implementation for other sizes.- Parameters:
m- The 2D double array to create the matrix from. A deep copy of this array is created to ensure the new matrix is independent of the original array.- Returns:
- A new
MatrixInterfaceimplementation containing a copy of the provided data. - Throws:
IllegalStateException- if the array is not a valid matrix structure (e.g., jagged rows, NaN values).
-
equalsRowsEqualCols
Checks if two matrices have the same number of rows and columns.- Parameters:
m1- The first matrix.m2- The second matrix.- Returns:
trueif both matrices have identical dimensions,falseotherwise.
-
add
Performs element-wise addition of two matrices.- Parameters:
m1- The first matrix.m2- The second matrix.- Returns:
- A new
MatrixInterfacecontaining the result of the addition. - Throws:
MatrixException- if the matrices do not have the same dimensions.
-
sub
Performs element-wise subtraction of two matrices (m1 - m2).- Parameters:
m1- The first matrix (minuend).m2- The second matrix (subtrahend).- Returns:
- A new
MatrixInterfacecontaining the result of the subtraction. - Throws:
MatrixException- if the matrices do not have the same dimensions.
-
mult
Performs matrix multiplication (m1 * m2). The number of columns in the first matrix must be equal to the number of rows in the second matrix.- Parameters:
m1- The first matrix.m2- The second matrix.- Returns:
- A new
MatrixInterfacecontaining the result of the multiplication. - Throws:
MatrixException- if the number of columns in m1 does not equal the number of rows in m2.
-