Variable MathUtilsConst

MathUtils: { DEG2RAD: number; RAD2DEG: number; ceilPowerOfTwo: ((value: number) => number); clamp: ((value: number, min: number, max: number) => number); damp: ((x: number, y: number, lambda: number, dt: number) => number); degToRad: ((degrees: number) => number); euclideanModulo: ((n: number, m: number) => number); floorPowerOfTwo: ((value: number) => number); generateUUID: (() => string); inverseLerp: ((x: number, y: number, value: number) => number); isPowerOfTwo: ((value: number) => boolean); lerp: ((x: number, y: number, t: number) => number); mapLinear: ((x: number, a1: number, a2: number, b1: number, b2: number) => number); pingpong: ((x: number, length?: number) => number); radToDeg: ((radians: number) => number); randFloat: ((low: number, high: number) => number); randFloatSpread: ((range: number) => number); randInt: ((low: number, high: number) => number); seededRandom: ((s?: number) => number); setQuaternionFromProperEuler: ((q: Quaternion, a: number, b: number, c: number, order: "XYX" | "XZX" | "YXY" | "YZY" | "ZXZ" | "ZYZ") => void); smootherstep: ((x: number, min: number, max: number) => number); smoothstep: ((x: number, min: number, max: number) => number) }

Type declaration

  • DEG2RAD: number
  • RAD2DEG: number
  • ceilPowerOfTwo: ((value: number) => number)
      • (value: number): number
      • Compute the smallest power of 2 that is greater than or equal to n.

        Returns

        The power of 2.

        Parameters

        • value: number

        Returns number

  • clamp: ((value: number, min: number, max: number) => number)
      • (value: number, min: number, max: number): number
      • Clamps the x to be between a and b.

        Parameters

        • value: number

          Value to be clamped.

        • min: number

          Minimum value

        • max: number

          Maximum value.

        Returns number

  • damp: ((x: number, y: number, lambda: number, dt: number) => number)
      • (x: number, y: number, lambda: number, dt: number): number
      • Smoothly interpolate a number from x toward y in a spring-like manner using the dt to maintain frame rate independent movement. http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/

        Parameters

        • x: number

          Current point.

        • y: number

          Target point.

        • lambda: number

          A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual.

        • dt: number

          Delta time in seconds.

        Returns number

  • degToRad: ((degrees: number) => number)
      • (degrees: number): number
      • Converts degrees to radians.

        Returns

        Radians

        Parameters

        • degrees: number

        Returns number

  • euclideanModulo: ((n: number, m: number) => number)
  • floorPowerOfTwo: ((value: number) => number)
      • (value: number): number
      • Compute the largest power of 2 that is less than or equal to n.

        Returns

        The power of 2.

        Parameters

        • value: number

        Returns number

  • generateUUID: (() => string)
      • (): string
      • Generate a UUID (universally unique identifier).

        Returns

        The UUID string.

        Returns string

  • inverseLerp: ((x: number, y: number, value: number) => number)
      • (x: number, y: number, value: number): number
      • Calculate the percentage in the closed interval [0, 1] of the given value between the start and end point.

        Returns

        The resulting percentage value.

        Parameters

        • x: number

          Start point.

        • y: number

          End point.

        • value: number

          A value between start and end.

        Returns number

  • isPowerOfTwo: ((value: number) => boolean)
      • (value: number): boolean
      • Determine if a value is a power of 2.

        Returnsv True

        if n is a power of 2.

        Parameters

        • value: number

          The value to test.

        Returns boolean

  • lerp: ((x: number, y: number, t: number) => number)
      • (x: number, y: number, t: number): number
      • Returns a value linearly interpolated from two known points based on the given interval - t = 0 will return x and t = 1 will return y. https://en.wikipedia.org/wiki/Linear_interpolation

        Parameters

        • x: number

          Start point.

        • y: number

          End point.

        • t: number

          interpolation factor in the closed interval [0, 1]

        Returns number

  • mapLinear: ((x: number, a1: number, a2: number, b1: number, b2: number) => number)
      • (x: number, a1: number, a2: number, b1: number, b2: number): number
      • Linear mapping of x from range [a1, a2] to range [b1, b2].

        Parameters

        • x: number

          Value to be mapped.

        • a1: number

          Minimum value for range A.

        • a2: number

          Maximum value for range A.

        • b1: number

          Minimum value for range B.

        • b2: number

          Maximum value for range B.

        Returns number

  • pingpong: ((x: number, length?: number) => number)
      • (x: number, length?: number): number
      • Returns a value that alternates between 0 and length. https://www.desmos.com/calculator/vcsjnyz7x4

        Parameters

        • x: number

          The value to pingpong.

        • Optional length: number

          The positive value the export function will pingpong to. Default is 1.

        Returns number

  • radToDeg: ((radians: number) => number)
      • (radians: number): number
      • Convert radians to degrees.

        Returns

        The degrees.

        Parameters

        • radians: number

          The radians to convert

        Returns number

  • randFloat: ((low: number, high: number) => number)
      • (low: number, high: number): number
      • Random float in the interval [low, high].

        Returns

        The random float.

        Parameters

        • low: number
        • high: number

        Returns number

  • randFloatSpread: ((range: number) => number)
      • (range: number): number
      • Random float in the interval [- range / 2, range / 2].

        Returns

        The random float.

        Parameters

        • range: number

        Returns number

  • randInt: ((low: number, high: number) => number)
      • (low: number, high: number): number
      • Random integer in the interval [low, high].

        Returns

        The random integer.

        Parameters

        • low: number
        • high: number

        Returns number

  • seededRandom: ((s?: number) => number)
      • (s?: number): number
      • Deterministic pseudo-random float in the interval [ 0, 1 ].

        Returns

        The random number

        Parameters

        • Optional s: number

          The seed

        Returns number

  • setQuaternionFromProperEuler: ((q: Quaternion, a: number, b: number, c: number, order: "XYX" | "XZX" | "YXY" | "YZY" | "ZXZ" | "ZYZ") => void)
      • (q: Quaternion, a: number, b: number, c: number, order: "XYX" | "XZX" | "YXY" | "YZY" | "ZXZ" | "ZYZ"): void
      • Sets quaternion q from the intrinsic Proper Euler Angles defined by angles a, b, and c, and order order. Rotations are applied to the axes in the order specified by order: rotation by angle a is applied first, then by angle b, then by angle c. Angles are in radians.

        Parameters

        • q: Quaternion

          the quaternion to be set

        • a: number

          the rotation applied to the first axis, in radians

        • b: number

          the rotation applied to the second axis, in radians

        • c: number

          the rotation applied to the third axis, in radians

        • order: "XYX" | "XZX" | "YXY" | "YZY" | "ZXZ" | "ZYZ"

          a string specifying the axes order: 'XYX', 'XZX', 'YXY', 'YZY', 'ZXZ', or 'ZYZ'

        Returns void

  • smootherstep: ((x: number, min: number, max: number) => number)
      • (x: number, min: number, max: number): number
      • Compute a value between 0-1. A variation on smoothstep that has zero 1st and 2nd order derivatives at x=0 and x=1.

        Returns

        The step value.

        Parameters

        • x: number

          The value to evaluate based on its position between min and max.

        • min: number

          Any x value below min will be 0.

        • max: number

          Any x value above max will be 1.

        Returns number

  • smoothstep: ((x: number, min: number, max: number) => number)
      • (x: number, min: number, max: number): number
      • Calculate 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. http://en.wikipedia.org/wiki/Smoothstep

        Returns

        The value.

        Parameters

        • x: number

          The value to evaluate based on its position between min and max.

        • min: number

          Any x value below min will be 0.

        • max: number

          Any x value above max will be 1.

        Returns number