dacha
    Preparing search index...

    Class MathOps

    Utility class providing static methods for mathematical operations.

    This class contains mathematical operations for working with 2D points and vectors. All methods are static and can be used without instantiating the class.

    const point = { x: 3, y: 4 };
    const distance = MathOps.getDistanceBetweenTwoPoints(point, point);
    Index
    • Clamps a value between a minimum and a maximum value.

      Parameters

      • value: number

        Value to clamp

      • min: number

        Minimum value

      • max: number

        Maximum value

      Returns number

      Clamped value

      const clamped = MathOps.clamp(10, 0, 5); // returns 5
      
    • Converts degrees to radians.

      Parameters

      • deg: number

        Angle in degrees

      Returns number

      Angle in radians

      const angle = MathOps.degToRad(90);
      
    • Calculates the angle between two points, in radians.

      Parameters

      • x1: number

        X coordinate of the first point

      • x2: number

        X coordinate of the second point

      • y1: number

        Y coordinate of the first point

      • y2: number

        Y coordinate of the second point

      Returns number

      Angle in radians

      const angle = MathOps.getAngleBetweenTwoPoints(10, 20, 30, 40);
      
    • Signed shortest angular difference between two angles in radians

      The result is in (-PI, PI], so from + delta is angle-equivalent to to while rotating the short way around.

      Parameters

      • from: number

        Start angle in radians

      • to: number

        End angle in radians

      Returns number

      Signed delta in radians

      const delta = MathOps.getAngleDelta(3, -3); // ~0.283, crosses PI
      
    • Calculates the distance between two points.

      Parameters

      • x1: number

        X coordinate of the first point

      • x2: number

        X coordinate of the second point

      • y1: number

        Y coordinate of the first point

      • y2: number

        Y coordinate of the second point

      Returns number

      Distance between the two points

      const distance = MathOps.getDistanceBetweenTwoPoints(10, 20, 30, 40);
      
    • Calculates a point on a line.

      Parameters

      • angle: number

        Angle of the line in degrees

      • x: number

        X coordinate of the line start point

      • y: number

        Y coordinate of the line start point

      • length: number

        Distance from the start point to the point on the line

      Returns Point

      Point on the line

      const point = MathOps.getLinePoint(45, 10, 20, 10);
      
    • Converts radians to degrees.

      Parameters

      • rad: number

        Angle in radians

      Returns number

      Angle in degrees

      const angle = MathOps.radToDeg(Math.PI / 2);
      
    • Generates a random number in the [min, max] range.

      Parameters

      • min: number

        Minimum value

      • max: number

        Maximum value

      Returns number

      A random number in [min, max] range

      const random = MathOps.random(0, 10);