Variable MathUtilsConst

MathUtils: { DEG2RAD: number; RAD2DEG: number; ceilPowerOfTwo: any; clamp: any; damp: any; degToRad: any; euclideanModulo: any; floorPowerOfTwo: any; generateUUID: any; inverseLerp: any; isPowerOfTwo: any; lerp: any; mapLinear: any; pingpong: any; radToDeg: any; randFloat: any; randFloatSpread: any; randInt: any; seededRandom: any; setQuaternionFromProperEuler: any; smootherstep: any; smoothstep: any } = ...

Type declaration

  • DEG2RAD: number
  • RAD2DEG: number
  • ceilPowerOfTwo:function
    • ceilPowerOfTwo(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:function
    • clamp(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:function
    • damp(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:function
    • degToRad(degrees: number): number
    • Converts degrees to radians.

      Returns

      Radians

      Parameters

      • degrees: number

      Returns number

  • euclideanModulo:function
    • euclideanModulo(n: number, m: number): number
  • floorPowerOfTwo:function
    • floorPowerOfTwo(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:function
    • generateUUID(): string
    • Generate a UUID (universally unique identifier).

      Returns

      The UUID string.

      Returns string

  • inverseLerp:function
    • inverseLerp(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:function
    • isPowerOfTwo(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:function
    • lerp(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:function
    • mapLinear(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:function
    • pingpong(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.

      • length: number = 1

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

      Returns number

  • radToDeg:function
    • radToDeg(radians: number): number
    • Convert radians to degrees.

      Returns

      The degrees.

      Parameters

      • radians: number

        The radians to convert

      Returns number

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

      Returns

      The random float.

      Parameters

      • low: number
      • high: number

      Returns number

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

      Returns

      The random float.

      Parameters

      • range: number

      Returns number

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

      Returns

      The random integer.

      Parameters

      • low: number
      • high: number

      Returns number

  • seededRandom:function
    • seededRandom(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:function
    • setQuaternionFromProperEuler(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:function
    • smootherstep(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:function
    • smoothstep(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