Class MatrixHelper
java.lang.Object
com.marginallyclever.convenience.helpers.MatrixHelper
Convenience methods for matrixes
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic javax.vecmath.Matrix4d
static Mesh
static javax.vecmath.Matrix4d
createScaleMatrix4
(double scale) static void
diagonalize
(javax.vecmath.Matrix3d a, javax.vecmath.Matrix3d dOut, javax.vecmath.Matrix3d qOut) returns Q and D such that Diagonal matrix D = QT * A * Q; and A = Q*D*QT see Jacobi_eigenvalue_algorithm see Diagonalizationstatic javax.vecmath.Matrix3d
eulerToMatrix
(javax.vecmath.Vector3d radians, MatrixHelper.EulerSequence sequenceIndex) Converts Euler angles to a rotation matrix based on the specified Euler sequence.static double[]
getCartesianBetweenTwoMatrices
(javax.vecmath.Matrix4d mStart, javax.vecmath.Matrix4d mEnd) Use Quaternions to estimate the distance between two matrixes (both linear and rotational).static void
getCartesianBetweenTwoMatrices
(javax.vecmath.Matrix4d mStart, javax.vecmath.Matrix4d mEnd, double[] listOut) Use Quaternions to estimate the distance between two matrixes (both linear and rotational).static javax.vecmath.Matrix3d
getMatrixFromAxisAndRotation
(javax.vecmath.Vector3d axis, double degrees) see Wikipediastatic javax.vecmath.Vector3d
getPosition
(javax.vecmath.Matrix4d m) static javax.vecmath.Vector3d
getXAxis
(javax.vecmath.Matrix4d m) static Plane
getXYPlane
(javax.vecmath.Matrix4d pivot) static javax.vecmath.Vector3d
getYAxis
(javax.vecmath.Matrix4d m) static javax.vecmath.Vector3d
getZAxis
(javax.vecmath.Matrix4d m) static boolean
interpolate
(javax.vecmath.Matrix4d start, javax.vecmath.Matrix4d end, double alpha, javax.vecmath.Matrix4d result) Interpolate between two 4d matrixes, (end-start)*i + start where i=[0...1]static javax.vecmath.Matrix3d
lookAt
(javax.vecmath.Vector3d from, javax.vecmath.Vector3d to) Build a "look at" matrix.static javax.vecmath.Matrix4d
lookAt
(javax.vecmath.Vector3d from, javax.vecmath.Vector3d to, javax.vecmath.Vector3d up) Build a "look at" matrix.static javax.vecmath.Vector3d
matrixToEuler
(javax.vecmath.Matrix3d mat, MatrixHelper.EulerSequence sequenceIndex) Assumes the rotational component is a valid rotation matrix.static javax.vecmath.Vector3d
matrixToEuler
(javax.vecmath.Matrix4d mat, MatrixHelper.EulerSequence sequenceIndex) Convenience method to call matrixToEuler() with only the rotational component.static void
normalize3
(javax.vecmath.Matrix4d mTarget) normalize the 3x3 component of the mTarget matrix.static javax.vecmath.Matrix4d
orthographicMatrix4d
(double left, double right, double bottom, double top, double near, double far) static javax.vecmath.Matrix4d
perspectiveMatrix4d
(double fovY, double aspect, double near, double far) static void
setPosition
(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v) static void
setXAxis
(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v) static void
setYAxis
(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v) static void
setZAxis
(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v)
-
Constructor Details
-
MatrixHelper
public MatrixHelper()
-
-
Method Details
-
createScaleMatrix4
public static javax.vecmath.Matrix4d createScaleMatrix4(double scale) -
createMesh
-
matrixToEuler
public static javax.vecmath.Vector3d matrixToEuler(javax.vecmath.Matrix4d mat, MatrixHelper.EulerSequence sequenceIndex) Convenience method to call matrixToEuler() with only the rotational component. Assumes the rotational component is a valid rotation matrix. Eulers are using the YXZ convention.- Parameters:
mat
- the Matrix4d to convert.- Returns:
- a valid Euler solution to the matrix.
-
matrixToEuler
public static javax.vecmath.Vector3d matrixToEuler(javax.vecmath.Matrix3d mat, MatrixHelper.EulerSequence sequenceIndex) Assumes the rotational component is a valid rotation matrix. Eulers are using the YXZ convention.- Parameters:
mat
- the Matrix3d to convert.sequenceIndex
- aMatrixHelper.EulerSequence
value.- Returns:
- a valid Euler solution to the matrix.
-
eulerToMatrix
public static javax.vecmath.Matrix3d eulerToMatrix(javax.vecmath.Vector3d radians, MatrixHelper.EulerSequence sequenceIndex) Converts Euler angles to a rotation matrix based on the specified Euler sequence. See also ...- Parameters:
radians
- radian rotation valuessequenceIndex
- aMatrixHelper.EulerSequence
value- Returns:
- resulting matrix
-
interpolate
public static boolean interpolate(javax.vecmath.Matrix4d start, javax.vecmath.Matrix4d end, double alpha, javax.vecmath.Matrix4d result) Interpolate between two 4d matrixes, (end-start)*i + start where i=[0...1]- Parameters:
start
- start matrixend
- end matrixalpha
- double value in the range [0...1]result
- where to store the resulting matrix- Returns:
- True if the operation succeeds. False if the inputs are bad or the operation fails.
-
lookAt
public static javax.vecmath.Matrix3d lookAt(javax.vecmath.Vector3d from, javax.vecmath.Vector3d to) Build a "look at" matrix. The X+ axis is pointing (to-from) normalized. The Z+ starts as pointing up. Y+ is cross product of X and Z. Z is then recalculated based on the correct X and Y. This will fail if to-from is parallel to up.- Parameters:
from
- where i'm atto
- what I'm looking at- Returns:
- a matrix that will transform a point to the "look at" orientation
-
lookAt
public static javax.vecmath.Matrix4d lookAt(javax.vecmath.Vector3d from, javax.vecmath.Vector3d to, javax.vecmath.Vector3d up) Build a "look at" matrix. The X+ axis is pointing (to-from) normalized. The Z+ starts as pointing up. Y+ is cross product of X and Z. Z is then recalculated based on the correct X and Y. This will fail if to-from is parallel to up.- Parameters:
from
- where i'm atto
- what I'm looking at- Returns:
- a matrix that will transform a point to the "look at" orientation
-
getXAxis
public static javax.vecmath.Vector3d getXAxis(javax.vecmath.Matrix4d m) -
getYAxis
public static javax.vecmath.Vector3d getYAxis(javax.vecmath.Matrix4d m) -
getZAxis
public static javax.vecmath.Vector3d getZAxis(javax.vecmath.Matrix4d m) -
getPosition
public static javax.vecmath.Vector3d getPosition(javax.vecmath.Matrix4d m) -
setXAxis
public static void setXAxis(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v) -
setYAxis
public static void setYAxis(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v) -
setZAxis
public static void setZAxis(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v) -
setPosition
public static void setPosition(javax.vecmath.Matrix4d m, javax.vecmath.Vector3d v) -
normalize3
public static void normalize3(javax.vecmath.Matrix4d mTarget) normalize the 3x3 component of the mTarget matrix. Do not affect position.- Parameters:
mTarget
- the matrix that will be normalized.
-
createIdentityMatrix4
public static javax.vecmath.Matrix4d createIdentityMatrix4() -
getMatrixFromAxisAndRotation
public static javax.vecmath.Matrix3d getMatrixFromAxisAndRotation(javax.vecmath.Vector3d axis, double degrees) see Wikipedia- Parameters:
axis
- a normalized vectordegrees
- angle in degrees- Returns:
- a rotation matrix
-
diagonalize
public static void diagonalize(javax.vecmath.Matrix3d a, javax.vecmath.Matrix3d dOut, javax.vecmath.Matrix3d qOut) returns Q and D such that Diagonal matrix D = QT * A * Q; and A = Q*D*QT see Jacobi_eigenvalue_algorithm see Diagonalization- Parameters:
a
- a symmetric matrix.dOut
- where to store the resultsqOut
- where to store the results
-
getCartesianBetweenTwoMatrices
public static double[] getCartesianBetweenTwoMatrices(javax.vecmath.Matrix4d mStart, javax.vecmath.Matrix4d mEnd) Use Quaternions to estimate the distance between two matrixes (both linear and rotational).- Parameters:
mStart
- matrix of start posemEnd
- matrix of end pose- Returns:
- 6 doubles that will be filled with the XYZ translation and RPY rotation.
-
getCartesianBetweenTwoMatrices
public static void getCartesianBetweenTwoMatrices(javax.vecmath.Matrix4d mStart, javax.vecmath.Matrix4d mEnd, double[] listOut) Use Quaternions to estimate the distance between two matrixes (both linear and rotational).- Parameters:
mStart
- matrix of start posemEnd
- matrix of end poselistOut
- a double[6] to store the result. Must not be null.
-
getXYPlane
-
orthographicMatrix4d
public static javax.vecmath.Matrix4d orthographicMatrix4d(double left, double right, double bottom, double top, double near, double far) -
perspectiveMatrix4d
public static javax.vecmath.Matrix4d perspectiveMatrix4d(double fovY, double aspect, double near, double far)
-