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
readonlystaticHALF_PI:number
Defined in: src/sdk/math/MathUtils.ts:18
One half the value of pi.
QUARTER_PI
readonlystaticQUARTER_PI:number
Defined in: src/sdk/math/MathUtils.ts:24
One quarter the value of pi.
SIXTH_PI
readonlystaticSIXTH_PI:number
Defined in: src/sdk/math/MathUtils.ts:27
One sixth the value of pi.
SQRT1_3
readonlystaticSQRT1_3:number
Defined in: src/sdk/math/MathUtils.ts:33
Square root of 1/3.
SQRT3
readonlystaticSQRT3:number
Defined in: src/sdk/math/MathUtils.ts:30
Square root of 3.
THIRD_PI
readonlystaticTHIRD_PI:number
Defined in: src/sdk/math/MathUtils.ts:21
One third the value of pi.
TWO_PI
readonlystaticTWO_PI:number
Defined in: src/sdk/math/MathUtils.ts:15
Twice the value of pi.
Methods
angularDistance()
staticangularDistance(startRadians,endRadians,direction):number
Defined in: src/sdk/math/MathUtils.ts:109
Gets the angular distance, in radians, swept from an starting angle to an ending angle.
Parameters
| Parameter | Type | Description |
|---|---|---|
startRadians | number | The starting angle, in radians. |
endRadians | number | The ending angle, in radians. |
direction | number | The direction to sweep from start to end. A positive value indicates sweeping in the direction of increasing angle. A negative value indicates sweeping in the direction of decreasing angle. A value of zero indicates that the direction should be chosen to produce the smallest angular distance. |
Returns
number
The angular distance, in radians, swept from the specified starting angle to the ending angle in the specified direction.
angularDistanceDeg()
staticangularDistanceDeg(startDegrees,endDegrees,direction):number
Defined in: src/sdk/math/MathUtils.ts:125
Gets the angular distance, in degrees, swept from an starting angle to an ending angle.
Parameters
| Parameter | Type | Description |
|---|---|---|
startDegrees | number | The starting angle, in degrees. |
endDegrees | number | The ending angle, in degrees. |
direction | number | The direction to sweep from start to end. A positive value indicates sweeping in the direction of increasing angle. A negative value indicates sweeping in the direction of decreasing angle. A value of zero indicates that the direction should be chosen to produce the smallest angular distance. |
Returns
number
The angular distance, in degrees, swept from the specified starting angle to the ending angle in the specified direction.
ceil()
staticceil(value,precision):number
Defined in: src/sdk/math/MathUtils.ts:63
Ceils a number.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | The number to ceil. |
precision | number | 1 | The precision with which to ceil. Defaults to 1. |
Returns
number
The ceiled number.
clamp()
staticclamp(value,min,max):number
Defined in: src/sdk/math/MathUtils.ts:43
Clamps a numerical value to the min/max range.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | number | The value to be clamped. |
min | number | The minimum. |
max | number | The maximum. |
Returns
number
The clamped numerical value..
diffAngle()
staticdiffAngle(start,end,directional):number
Defined in: src/sdk/math/MathUtils.ts:141
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
start | number | undefined | The starting angle, in radians. |
end | number | undefined | The ending angle, in radians. |
directional | boolean | true | Whether 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()
staticdiffAngleDeg(start,end,directional):number
Defined in: src/sdk/math/MathUtils.ts:155
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
start | number | undefined | The starting angle, in degrees. |
end | number | undefined | The ending angle, in degrees. |
directional | boolean | true | Whether 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()
staticdriveExp(initialValue,targetValue,timeConstant,dt):number
Defined in: src/sdk/math/MathUtils.ts:251
Drives an initial value toward a target value via an exponential decay curve over a period of time.
Parameters
| Parameter | Type | Description |
|---|---|---|
initialValue | number | The initial value. |
targetValue | number | The target value. |
timeConstant | number | The exponential decay time constant, in the same units as dt. Must be a positive number. |
dt | number | The amount of time over which to drive the value. |
Returns
number
The final driven value after the specified amount of time has elapsed.
driveLinear()
staticdriveLinear(initialValue,targetValue,rate,dt,clampStart,clampEnd):number
Defined in: src/sdk/math/MathUtils.ts:227
Drives an initial value toward a target value linearly over a period of time.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
initialValue | number | undefined | The initial value. |
targetValue | number | undefined | The target value. |
rate | number | undefined | The rate at which to drive the value, in the same units as dt. |
dt | number | undefined | The amount of time over which to drive the value. |
clampStart | boolean | true | Whether to clamp the driven value such that it cannot be driven in the opposite direction from the target value. Defaults to true. |
clampEnd | boolean | true | Whether 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()
staticfloor(value,precision):number
Defined in: src/sdk/math/MathUtils.ts:73
Floors a number.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | The number to floor. |
precision | number | 1 | The precision with which to floor. Defaults to 1. |
Returns
number
The floored number.
hardSign()
statichardSign(n):number
Defined in: src/sdk/math/MathUtils.ts:211
Gets the sign of a number, including 0.
Parameters
| Parameter | Type | Description |
|---|---|---|
n | number | The 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()
staticlerp(x,x0,x1,y0,y1,clampStart,clampEnd):number
Defined in: src/sdk/math/MathUtils.ts:170
Linearly interpolates a keyed value along one dimension.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
x | number | undefined | The key of the value to interpolate. |
x0 | number | undefined | The key of the first known value. |
x1 | number | undefined | The key of the second known value. |
y0 | number | undefined | The first known value. |
y1 | number | undefined | The second known value. |
clampStart | boolean | false | Whether to clamp the interpolated value to the first known value. Defaults to false. |
clampEnd | boolean | false | Whether to clamp the interpolated value to the second known value. Defaults to false. |
Returns
number
The interpolated value corresponding to the specified key.
lerpVector()
staticlerpVector(out,x,x0,x1,y0,y1,clampStart,clampEnd):Float64Array
Defined in: src/sdk/math/MathUtils.ts:194
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
| Parameter | Type | Default value | Description |
|---|---|---|---|
out | Float64Array | undefined | The object to which to write the result. |
x | number | undefined | The key of the vector to interpolate. |
x0 | number | undefined | The key of the first known vector. |
x1 | number | undefined | The key of the second known vector. |
y0 | ArrayLike<number> | undefined | The first known vector. |
y1 | ArrayLike<number> | undefined | The second known vector. |
clampStart | boolean | false | Whether to clamp the components of the interpolated vector to those of the first known vector. Defaults to false. |
clampEnd | boolean | false | Whether 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.
normalizeAngle()
staticnormalizeAngle(radians,lowerBound):number
Defined in: src/sdk/math/MathUtils.ts:84
Normalizes an angle in radians.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
radians | number | undefined | The angle to normalize, in radians. |
lowerBound | number | 0 | The lower bound of the normalized angle, in radians. The normalized angle will fall in the range [lowerBound, lowerBound + 2 * pi). Defaults to 0. |
Returns
number
The specified angle after normalization, in radians.
normalizeAngleDeg()
staticnormalizeAngleDeg(degrees,lowerBound):number
Defined in: src/sdk/math/MathUtils.ts:95
Normalizes an angle in degrees.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
degrees | number | undefined | The angle to normalize, in degrees. |
lowerBound | number | 0 | The lower bound of the normalized angle, in degrees. The normalized angle will fall in the range [lowerBound, lowerBound + 360). Defaults to 0. |
Returns
number
The specified angle after normalization, in degrees.
round()
staticround(value,precision):number
Defined in: src/sdk/math/MathUtils.ts:53
Rounds a number.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | The number to round. |
precision | number | 1 | The precision with which to round. Defaults to 1. |
Returns
number
The rounded number.