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)
Checks whether the matrix columns are mutually perpendicular unit vectors.
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)
Returns a unit vector perpendicular 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 nonzero.
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 whether a matrix represents a rotation without scaling or reflection.
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.
public static JMatrix PseudoInverseSymmetric(in JMatrix matrix)
Parameters
matrixJMatrixA finite, symmetric, positive-semidefinite matrix.
Returns
- JMatrix
The approximate inverse, with singular directions left at zero.
Remarks
Uses a relative tolerance of 1e-6 in both precisions to identify nearly singular matrices and discard small eigenvalues. The tolerance is relative to the largest absolute diagonal entry. A zero matrix returns a zero matrix. The input must be symmetric and positive semidefinite; these conditions are not checked.
RotationQuaternion(in JVector, float)
Calculates the rotation produced by a constant angular velocity over a time interval.
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.