Table of Contents

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

matrix JMatrix

The input matrix to check.

epsilon float

The tolerance for floating-point comparisons.

Returns

bool

true if the columns are mutually perpendicular and have unit length; otherwise, false.

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

v JVector

The vector to evaluate.

epsilonSq float

Threshold for squared magnitude.

Returns

bool

true if the squared length is less than epsilonSq; otherwise, false.

CreateOrthonormal(in JVector)

Calculates an orthonormal vector to the given vector.

public static JVector CreateOrthonormal(in JVector vec)

Parameters

vec JVector

The 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)

Calculates (MᵀM)^(-1/2) using Jacobi iterations.

public static JMatrix InverseSquareRoot(JMatrix m, int sweeps = 2)

Parameters

m JMatrix

The input matrix.

sweeps int

The number of Jacobi iterations.

Returns

JMatrix

The inverse square root of Mᵀ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

matrix JMatrix

The matrix to check.

epsilon float

The tolerance for floating-point comparisons.

Returns

bool

true if the matrix is orthonormal with determinant 1; otherwise, false.

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

vector JVector

The vector to check.

epsilon float

The tolerance for each component.

Returns

bool

true if all components are within epsilon of zero; otherwise, false.

IsZero(float, float)

Checks if a value is close to zero.

public static bool IsZero(float value, float epsilon = 1E-06)

Parameters

value float

The value to check.

epsilon float

The tolerance.

Returns

bool

true if the absolute value is less than epsilon; otherwise, false.

RotationQuaternion(in JVector, float)

Calculates the rotation quaternion corresponding to the given (constant) angular velocity vector and time step.

public static JQuaternion RotationQuaternion(in JVector omega, float dt)

Parameters

omega JVector

The angular velocity vector in radians per second.

dt float

The time step in seconds.

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

value double

The number to test.

Returns

int

+1 when the sign bit is clear (positive, +0, or a positive-sign NaN), -1 when the sign bit is set (negative, −0, or a negative-sign NaN). Never returns 0, unlike Sign(float).

SignBit(float)

Gets the sign of value purely from its IEEE-754 sign bit.

public static int SignBit(float value)

Parameters

value float

The number to test.

Returns

int

+1 when the sign bit is clear (positive, +0, or a positive-sign NaN), -1 when the sign bit is set (negative, −0, or a negative-sign NaN). Never returns 0, 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

matrix JMatrix

The matrix to check.

epsilon float

The tolerance for each element.

Returns

bool

true if all elements are within epsilon of zero; otherwise, false.