Static ReadonlyDeg2Constant that converts degrees to radians.
Static ReadonlyHalfHalf of pi constant.
Static ReadonlyPiPi constant.
Static ReadonlyRad2Constant that converts radians to degrees.
Static ReadonlyTwoTwo times pi constant.
StaticacosStaticasinStaticatanStaticatan2StaticcalculateCalculates the point at t of the Cubic Bezier curve in 2D-space.
The starting point of the Bezier curve.
The first cubic Bezier control point.
The second cubic Bezier control point.
The ending point of the Bezier curve.
The point at which to calculate the curve derivative for. Must be in the range [0, 1].
The tangent vector to at the desired point.
StaticcalculateCalculates the point at t of the Cubic Bezier curve in 3D-space.
The starting point of the Bezier curve.
The first cubic Bezier control point.
The second cubic Bezier control point.
The ending point of the Bezier curve.
The point at which to calculate the curve derivative for. Must be in the range [0, 1].
The tangent vector to at the desired point.
StaticcalculateCalculates the tangent at point t of the Cubic Bezier curve.
The starting point of the Bezier curve.
The first cubic Bezier control point.
The second cubic Bezier control point.
The ending point of the Bezier curve.
The point at which to calculate the curve derivative for. Must be in the range [0, 1].
The tangent vector to at the desired point.
StaticcalculateCalculates the tangent at point t of the Cubic Bezier curve.
The starting point of the Bezier curve.
The first cubic Bezier control point.
The second cubic Bezier control point.
The ending point of the Bezier curve.
The point at which to calculate the curve derivative for. Must be in the range [0, 1].
The tangent vector to at the desired point.
StaticcbrtReturn a cubic root of the provided value.
Value to take the cubic root of.
Cubic root of the provided value.
StaticclampStaticclamp01StaticcosStaticcubicPerforms cubic interpolation between two values bound between two other values where f is
the alpha value in range [0, 1]. If it is 0 the method returns val2. If it is 1 the
method returns val3.
First value.
Second value.
Third value.
Fourth value.
Value in range [0, 1].
Value resulting from cubic interpolation.
Staticdegrees2Converts the value in degrees to radians.
StaticdivideStaticevalEvaluates the specified math expression and returns the result.
A vector type containing the result of the expression.
This is a helper to make writing math expressions in Javascript easier. There is a slight overhead compared to doing math expressions manually as the expression must be evaluted N-times for each component of the vector type. However, the cost amortizes well as no temporary objects must be constructed that hold the result. The expression is evaluated using only numbers, and then assigned to the respective component of the vector result.
The fastest possible way of doing math is still using the do math type APIs such as doAdd as these APIs will
avoid the construction of a temporary object, but will instead, apply the expression on the calling object
and return a reference to the same object. This allows to quickly chain a math expression together.
To make a variable evaluatable it must either be casted to the Evaluatable<T> type where T is an
evaluatable type such as Vector3.
Alternatively, the variable can be prefixed with the unary plus
to allow the compiler to use the variable in the expression.
The following example shows basic usage:
// This vector is marked as `Evaluatable` and can be directly referenced in the expression.
const myVector = new Vector3(10, 20, 30) as Evaluatable<Vector3>;
// This vector is not evaluatable, it must be prefixed with the `unary plus`.
const myVector2 = new Vector3(-10, -20, 20);
const result:Vector3 = MathEx.eval(Vector3, () => (myVector + +myVector2) * 2)
The result in the above example will be [0, 0, 100].
It's important to note that performing function invocations can dramatic overhead as the
function must be invoked once for each component of the resultType.
The following example shows a bad practice and should be avoided.
const result:Vector3 = MathEx.eval(Vector3, () => myVector.normalized() * myVector2)
The normalized function will be slowing down the execution as it must be invoked once for each
component of the resultType. In the case of the Vector3 it results in calling the expensive function three times.
While calling eval recursively, it results in evaluating the sub expression once for each component.
So calling eval inside of a Vector3 evaluation for a Vector3 type results in 3 * 3 invocations.
StaticfractReturns the fractional part of the provided value.
Parameter to take fractional value from.
Fractional value of value.
StaticinverseReturns an inverse square root (1/sqrt(x)) of the provided value.
Value to take the inverse square root of. Must not be negative or zero.
Inverse square root of the provided value.
StaticisCompares two numbers with an error margin.
First number to compare.
Second number to compare.
Optionalepsilon: number
Error margin within which the numbers should be considered equal.
True if equal, false otherwise.
StaticlerpStaticlog10Returns the logarithm of a number in base 10.
Value to get the logarithm of.
Logarithm of a number in base 10.
StaticlogReturns the logarithm of a number in a specified base.
Value to get the logarithm of.
Base of the logarithm
Logarithm of a number in the specified base.
StaticmaxStaticminStaticmoduloReturns dividend % divisor (floating point modulo).
Value to repeat.
Length after which to repeat the value.
Result of f % length.
StaticnormalizeNormalize the value between based on the range. Returns 0 if f is less or
equal that minimum, 1 if f is equal or greater than maximum, and value in range (0, 1) otherwise.
Value to take inverse lerp of.
Minimum value of the range.
Maximum value of the range.
The normalized value.
StaticpingWraps the value in range [0, length] and reverses the direction every
length increment. This results in f incrementing until length, then
decrementing back to 0, and so on.
Value to ping-pong.
Length after which to reverse the direction.
Result of the ping-pong operation.
StaticquinticPerforms quintic interpolation where value is the value to map onto a quintic S-curve.
Value in range [0, 1].
Value resulting from quintic interpolation.
Staticradians2Converts the value in radians to degrees.
StaticroundRounds to the nearest multiple.
Value to round.
Multiple to round to.
Value rounded to the nearest multiple.
StaticsignReturns the sign of the provided value (positive or negative).
Value to get the sign of.
-1.0f if negative or 1.0f if positive.
StaticsinStaticsmoothPerforms smooth Hermite interpolation between values.
First value.
Second Value.
Value in range [0, 1] that determines how much to interpolate.
Hermite interpolated value at position t.
StatictanStaticwrap
The MathEx class provides additional helpers utility function for math operations. It extends the built-in Math class with additional functionality.