Skip to main content

Class: MathUtils

Defined in: src/sdk/math/MathUtils.ts:13

A utitlity class for basic math.

Constructors​

Constructor​

new MathUtils(): MathUtils

Returns​

MathUtils

Properties​

HALF_PI​

readonly static HALF_PI: number

Defined in: src/sdk/math/MathUtils.ts:18

Half the value of pi.


SQRT1_3​

readonly static SQRT1_3: number

Defined in: src/sdk/math/MathUtils.ts:24

Square root of 1/3.


SQRT3​

readonly static SQRT3: number

Defined in: src/sdk/math/MathUtils.ts:21

Square root of 3.


TWO_PI​

readonly static TWO_PI: number

Defined in: src/sdk/math/MathUtils.ts:15

Twice the value of pi.

Methods​

ceil()​

static ceil(value, precision): number

Defined in: src/sdk/math/MathUtils.ts:54

Ceils a number.

Parameters​

ParameterTypeDefault valueDescription
valuenumberundefinedThe number to ceil.
precisionnumber1The precision with which to ceil. Defaults to 1.

Returns​

number

The ceiled number.


clamp()​

static clamp(value, min, max): number

Defined in: src/sdk/math/MathUtils.ts:34

Clamps a numerical value to the min/max range.

Parameters​

ParameterTypeDescription
valuenumberThe value to be clamped.
minnumberThe minimum.
maxnumberThe maximum.

Returns​

number

The clamped numerical value..


diffAngle()​

static diffAngle(start, end, directional): number

Defined in: src/sdk/math/MathUtils.ts:78

Calculates the angular difference between two angles in the range [0, 2 * pi). The calculation supports both directional and non-directional differences. The directional difference is the angle swept from the start angle to the end angle proceeding in the direction of increasing angle. The non-directional difference is the smaller of the two angles swept from the start angle to the end angle proceeding in either direction.

Parameters​

ParameterTypeDefault valueDescription
startnumberundefinedThe starting angle, in radians.
endnumberundefinedThe ending angle, in radians.
directionalbooleantrueWhether to calculate the directional difference. Defaults to true.

Returns​

number

The angular difference between the two angles, in radians, in the range [0, 2 * pi).


diffAngleDeg()​

static diffAngleDeg(start, end, directional): number

Defined in: src/sdk/math/MathUtils.ts:93

Calculates the angular difference between two angles in the range [0, 360). The calculation supports both directional and non-directional differences. The directional difference is the angle swept from the start angle to the end angle proceeding in the direction of increasing angle. The non-directional difference is the smaller of the two angles swept from the start angle to the end angle proceeding in either direction.

Parameters​

ParameterTypeDefault valueDescription
startnumberundefinedThe starting angle, in degrees.
endnumberundefinedThe ending angle, in degrees.
directionalbooleantrueWhether to calculate the directional difference. Defaults to true.

Returns​

number

The angular difference between the two angles, in degrees, in the range [0, 360).


driveExp()​

static driveExp(initialValue, targetValue, timeConstant, dt): number

Defined in: src/sdk/math/MathUtils.ts:190

Drives an initial value toward a target value via an exponential decay curve over a period of time.

Parameters​

ParameterTypeDescription
initialValuenumberThe initial value.
targetValuenumberThe target value.
timeConstantnumberThe exponential decay time constant, in the same units as dt. Must be a positive number.
dtnumberThe amount of time over which to drive the value.

Returns​

number

The final driven value after the specified amount of time has elapsed.


driveLinear()​

static driveLinear(initialValue, targetValue, rate, dt, clampStart, clampEnd): number

Defined in: src/sdk/math/MathUtils.ts:166

Drives an initial value toward a target value linearly over a period of time.

Parameters​

ParameterTypeDefault valueDescription
initialValuenumberundefinedThe initial value.
targetValuenumberundefinedThe target value.
ratenumberundefinedThe rate at which to drive the value, in the same units as dt.
dtnumberundefinedThe amount of time over which to drive the value.
clampStartbooleantrueWhether to clamp the driven value such that it cannot be driven in the opposite direction from the target value. Defaults to true.
clampEndbooleantrueWhether to clamp the driven value such that it cannot be driven past the target value. Defaults to true.

Returns​

number

The final driven value after the specified amount of time has elapsed.


floor()​

static floor(value, precision): number

Defined in: src/sdk/math/MathUtils.ts:64

Floors a number.

Parameters​

ParameterTypeDefault valueDescription
valuenumberundefinedThe number to floor.
precisionnumber1The precision with which to floor. Defaults to 1.

Returns​

number

The floored number.


hardSign()​

static hardSign(n): number

Defined in: src/sdk/math/MathUtils.ts:150

Gets the sign of a number, including 0.

Parameters​

ParameterTypeDescription
nnumberThe number to get the sign of.

Returns​

number

1.0 if the number is positive, +0 or Infinity; -1.0 if the number is negative, -0 or -Infinity; NaN if the number is NaN


lerp()​

static lerp(x, x0, x1, y0, y1, clampStart, clampEnd): number

Defined in: src/sdk/math/MathUtils.ts:109

Linearly interpolates a keyed value along one dimension.

Parameters​

ParameterTypeDefault valueDescription
xnumberundefinedThe key of the value to interpolate.
x0numberundefinedThe key of the first known value.
x1numberundefinedThe key of the second known value.
y0numberundefinedThe first known value.
y1numberundefinedThe second known value.
clampStartbooleanfalseWhether to clamp the interpolated value to the first known value. Defaults to false.
clampEndbooleanfalseWhether to clamp the interpolated value to the second known value. Defaults to false.

Returns​

number

The interpolated value corresponding to the specified key.


lerpVector()​

static lerpVector(out, x, x0, x1, y0, y1, clampStart, clampEnd): Float64Array

Defined in: src/sdk/math/MathUtils.ts:133

Linearly interpolates a keyed vector along one dimension. If the known vectors and the result vector have unequal lengths, then only the components shared by all vectors are interpolated in the result.

Parameters​

ParameterTypeDefault valueDescription
outFloat64ArrayundefinedThe object to which to write the result.
xnumberundefinedThe key of the vector to interpolate.
x0numberundefinedThe key of the first known vector.
x1numberundefinedThe key of the second known vector.
y0ArrayLike<number>undefinedThe first known vector.
y1ArrayLike<number>undefinedThe second known vector.
clampStartbooleanfalseWhether to clamp the components of the interpolated vector to those of the first known vector. Defaults to false.
clampEndbooleanfalseWhether to clamp the components of the interpolated vector to those of the second known vector. Defaults to false.

Returns​

Float64Array

The interpolated vector corresponding to the specified key.


round()​

static round(value, precision): number

Defined in: src/sdk/math/MathUtils.ts:44

Rounds a number.

Parameters​

ParameterTypeDefault valueDescription
valuenumberundefinedThe number to round.
precisionnumber1The precision with which to round. Defaults to 1.

Returns​

number

The rounded number.