Package jsim.core
Class Mat3
java.lang.Object
jsim.core.Mat3
Internal row-major 3x3 matrix math for deterministic physics.
Index layout: [0 1 2 / 3 4 5 / 6 7 8] where row r, col c = index r*3+c.
-
Method Summary
Modifier and TypeMethodDescriptionstatic double[]diagonal(double a, double b, double c) Returns a diagonal 3x3 matrix with the given diagonal elements.static double[]fromQuaternion(double qw, double qx, double qy, double qz) Build rotation matrix from unit quaternion (w, x, y, z).static double[]identity()Returns the 3x3 identity matrix as a 9-element row-major array.static double[]invert(double[] m) Invert a 3x3 matrix using Cramer's rule.static double[]mul(double[] a, double[] b) Multiply two 3x3 row-major matrices (a * b).static double[]mulVec(double[] m, double[] v) Multiply a 3x3 matrix by a 3-vector (m * v).static double[]rotateInertia(double[] R, double d0, double d1, double d2) Compute R * diag(d0,d1,d2) * R^T efficiently.static double[]transpose(double[] m) Transpose of a 3x3 row-major matrix.
-
Method Details
-
identity
public static double[] identity()Returns the 3x3 identity matrix as a 9-element row-major array.- Returns:
- identity matrix
-
diagonal
public static double[] diagonal(double a, double b, double c) Returns a diagonal 3x3 matrix with the given diagonal elements.- Parameters:
a- first diagonal elementb- second diagonal elementc- third diagonal element- Returns:
- 9-element row-major diagonal matrix
-
fromQuaternion
public static double[] fromQuaternion(double qw, double qx, double qy, double qz) Build rotation matrix from unit quaternion (w, x, y, z).- Parameters:
qw- quaternion W componentqx- quaternion X componentqy- quaternion Y componentqz- quaternion Z component- Returns:
- 3x3 row-major rotation matrix as a 9-element array
-
mulVec
public static double[] mulVec(double[] m, double[] v) Multiply a 3x3 matrix by a 3-vector (m * v).- Parameters:
m- 3x3 row-major matrix (9 elements)v- input vector (3 elements)- Returns:
- result vector (3 elements)
-
mul
public static double[] mul(double[] a, double[] b) Multiply two 3x3 row-major matrices (a * b).- Parameters:
a- left matrix (9 elements)b- right matrix (9 elements)- Returns:
- product matrix (9 elements)
-
transpose
public static double[] transpose(double[] m) Transpose of a 3x3 row-major matrix.- Parameters:
m- input matrix (9 elements)- Returns:
- transposed matrix (9 elements)
-
rotateInertia
public static double[] rotateInertia(double[] R, double d0, double d1, double d2) Compute R * diag(d0,d1,d2) * R^T efficiently. Used to transform body-frame diagonal inertia to world frame.- Parameters:
R- rotation matrix (9 elements, row-major)d0- first diagonal elementd1- second diagonal elementd2- third diagonal element- Returns:
- 3x3 result matrix (9 elements)
-
invert
public static double[] invert(double[] m) Invert a 3x3 matrix using Cramer's rule. Returns the identity matrix if the input is singular.- Parameters:
m- input matrix (9 elements, row-major)- Returns:
- inverted matrix (9 elements)
-