Class MathHelper
- Namespace
- Jitter2.LinearMath
- Assembly
- Jitter2.dll
Provides mathematical helper methods for linear algebra and physics calculations.
public static class MathHelper
- Inheritance
-
MathHelper
- Inherited Members
Methods
CheckOrthonormalBasis(in JMatrix, float)
Verifies whether the columns of the given matrix constitute an orthonormal basis.
public static bool CheckOrthonormalBasis(in JMatrix matrix, float epsilon = 1E-06)
Parameters
matrixJMatrixThe input matrix to check.
epsilonfloatThe tolerance for floating-point comparisons.
Returns
CloseToZero(in JVector, float)
Determines whether the length of the given vector is zero or close to zero.
public static bool CloseToZero(in JVector v, float epsilonSq = 1E-16)
Parameters
Returns
CreateOrthonormal(in JVector)
Calculates an orthonormal vector to the given vector.
public static JVector CreateOrthonormal(in JVector vec)
Parameters
vecJVectorThe input vector (must be non-zero, does not need to be normalized).
Returns
- JVector
A unit vector orthogonal to the input.
Remarks
The input vector must be non-zero. Debug builds assert this condition.
InverseSquareRoot(JMatrix, int)
Approximates M^(-1/2) for a symmetric positive-definite matrix using Jacobi iterations.
public static JMatrix InverseSquareRoot(JMatrix m, int sweeps = 2)
Parameters
Returns
- JMatrix
The approximate inverse square root of
M.
IsRotationMatrix(in JMatrix, float)
Checks if matrix is a pure rotation matrix.
public static bool IsRotationMatrix(in JMatrix matrix, float epsilon = 1E-06)
Parameters
Returns
IsZero(in JVector, float)
Checks if all entries of a vector are close to zero.
public static bool IsZero(in JVector vector, float epsilon = 1E-06)
Parameters
Returns
- bool
true if no component has an absolute value greater than or equal to epsilon; NaN components also satisfy this test.
IsZero(float, float)
Checks if a value is close to zero.
public static bool IsZero(float value, float epsilon = 1E-06)
Parameters
Returns
PseudoInverseSymmetric(in JMatrix)
Computes an approximate Moore-Penrose pseudoinverse of a symmetric, positive-semidefinite 3x3 matrix, such as a joint's inverse effective mass.
public static JMatrix PseudoInverseSymmetric(in JMatrix matrix)
Parameters
matrixJMatrixA finite, symmetric, positive-semidefinite matrix.
Returns
- JMatrix
The inverse on responsive directions, with zero response on discarded directions.
Remarks
Uses the ordinary inverse when the normalized determinant is sufficiently large. Otherwise, Jacobi diagonalization retains eigenvalues greater than a normalized tolerance of 1e-6 in single precision or 1e-12 in double precision. The normalization uses the largest absolute diagonal entry. A zero matrix produces a zero pseudoinverse. Symmetry and positive semidefiniteness are assumed and are not validated. Compute this during constraint preparation and cache the result for solver iterations.
RotationQuaternion(in JVector, float)
Calculates the rotation quaternion corresponding to the given angular velocity using deterministic trigonometric approximations.
public static JQuaternion RotationQuaternion(in JVector omega, float dt)
Parameters
Returns
- JQuaternion
A unit quaternion representing the rotation.
SignBit(double)
Gets the sign of value purely from its IEEE-754 sign bit.
public static int SignBit(double value)
Parameters
valuedoubleThe number to test.
Returns
- int
+1when the sign bit is clear (positive, +0, or a positive-sign NaN),-1when the sign bit is set (negative, −0, or a negative-sign NaN). Never returns0, unlike Sign(float).
SignBit(float)
Gets the sign of value purely from its IEEE-754 sign bit.
public static int SignBit(float value)
Parameters
valuefloatThe number to test.
Returns
- int
+1when the sign bit is clear (positive, +0, or a positive-sign NaN),-1when the sign bit is set (negative, −0, or a negative-sign NaN). Never returns0, unlike Sign(float).
UnsafeIsZero(ref JMatrix, float)
Checks if all entries of a matrix are close to zero.
public static bool UnsafeIsZero(ref JMatrix matrix, float epsilon = 1E-06)
Parameters
Returns
- bool
true if all rows satisfy IsZero(in JVector, float), including rows with NaN components.