Math

Math utility functions

Properties

Methods

.clamp ( value, min, max )

value — Value to be clamped.
min — Minimum value
max — Maximum value.
Clamps the value to be between min and max.

.mapLinear ( x, a1, a2, b1, b2 )

x — Value to be mapped.
a1 — Minimum value for range A.
a2 — Maximum value for range A.
b1 — Minimum value for range B.
b2 — Maximum value for range B.
Linear mapping of x from range [a1, a2] to range [b1, b2].

.random16 ()

Random float from 0 to 1 with 16 bits of randomness.
Standard Math.random() creates repetitive patterns when applied over larger space.

.randInt ( low, high )

Random integer from low to high interval.

.randFloat ( low, high )

Random float from low to high interval.

.randFloatSpread ( range )

Random float from - range / 2 to range / 2 interval.

.degToRad ( degrees )

degrees -- Float
Converts degrees to radians.

.radToDeg ( radians )

radians -- Float
Converts radians to degrees

.smoothstep ( x, min, max )

x -- The value to evaluate based on its position between min and max.
min -- Any x value below min will be 0
max -- Any x value above max will be 1
Returns a value between 0-1 that represents the percentage that x has moved between min and max, but smoothed or slowed down the closer X is to the min and max.

Wikipedia

.smootherstep ( x, min, max )

x -- The value to evaluate based on its position between min and max.
min -- Any x value below min will be 0
max -- Any x value above max will be 1
Returns a value between 0-1. It works the same as smoothstep, but more smooth.

Source

src/math/Math.js
Edit