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.
StaticcbrtStaticclampStaticclamp01StaticcosStaticcubicPerforms 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.
Staticdegrees2StaticdivideStaticevalEvaluates 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.
StaticfractStaticinverseStaticisStaticlerpStaticlog10StaticlogStaticmaxStaticminStaticmoduloStaticnormalizeNormalize 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.
StaticquinticStaticradians2StaticroundStaticsignStaticsinStaticsmoothStatictanStaticwrap
The MathEx class provides additional helpers utility function for math operations. It extends the built-in Math class with additional functionality.