Class MathUtils

java.lang.Object
ActiverseUtils.MathUtils

public class MathUtils extends Object
MathUtils - Common mathematical utility functions for game development
Version:
1.4.1
Author:
Knivier
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    angleBetween(double x1, double y1, double x2, double y2)
    Calculates angle between two points in radians
    static boolean
    approximately(double a, double b)
    Checks if a value is approximately equal to another (within 0.0001)
    static boolean
    approximately(double a, double b, double epsilon)
    Checks if a value is approximately equal to another (within epsilon)
    static double
    clamp(double value, double min, double max)
    Clamps a value between a minimum and maximum
    static float
    clamp(float value, float min, float max)
    Clamps a float value between a minimum and maximum
    static int
    clamp(int value, int min, int max)
    Clamps an integer value between a minimum and maximum
    static double
    distance(double x1, double y1, double x2, double y2)
    Calculates distance between two points
    static double
    lerp(double start, double end, double t)
    Linear interpolation between two values
    static double
    map(double value, double inMin, double inMax, double outMin, double outMax)
    Maps a value from one range to another
    static double
    normalizeAngle(double angle)
    Normalizes an angle to be within 0 to 2π radians
    static double
    toDegrees(double radians)
    Converts radians to degrees
    static double
    toRadians(double degrees)
    Converts degrees to radians

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MathUtils

      public MathUtils()
  • Method Details

    • lerp

      public static double lerp(double start, double end, double t)
      Linear interpolation between two values
      Parameters:
      start - Starting value
      end - Ending value
      t - Interpolation factor (0.0 to 1.0)
      Returns:
      Interpolated value
    • clamp

      public static double clamp(double value, double min, double max)
      Clamps a value between a minimum and maximum
      Parameters:
      value - The value to clamp
      min - Minimum value
      max - Maximum value
      Returns:
      Clamped value
    • clamp

      public static float clamp(float value, float min, float max)
      Clamps a float value between a minimum and maximum
      Parameters:
      value - The value to clamp
      min - Minimum value
      max - Maximum value
      Returns:
      Clamped value
    • clamp

      public static int clamp(int value, int min, int max)
      Clamps an integer value between a minimum and maximum
      Parameters:
      value - The value to clamp
      min - Minimum value
      max - Maximum value
      Returns:
      Clamped value
    • distance

      public static double distance(double x1, double y1, double x2, double y2)
      Calculates distance between two points
      Parameters:
      x1 - First point X
      y1 - First point Y
      x2 - Second point X
      y2 - Second point Y
      Returns:
      Distance between points
    • angleBetween

      public static double angleBetween(double x1, double y1, double x2, double y2)
      Calculates angle between two points in radians
      Parameters:
      x1 - First point X
      y1 - First point Y
      x2 - Second point X
      y2 - Second point Y
      Returns:
      Angle in radians
    • normalizeAngle

      public static double normalizeAngle(double angle)
      Normalizes an angle to be within 0 to 2π radians
      Parameters:
      angle - The angle in radians
      Returns:
      Normalized angle
    • toRadians

      public static double toRadians(double degrees)
      Converts degrees to radians
      Parameters:
      degrees - Angle in degrees
      Returns:
      Angle in radians
    • toDegrees

      public static double toDegrees(double radians)
      Converts radians to degrees
      Parameters:
      radians - Angle in radians
      Returns:
      Angle in degrees
    • approximately

      public static boolean approximately(double a, double b, double epsilon)
      Checks if a value is approximately equal to another (within epsilon)
      Parameters:
      a - First value
      b - Second value
      epsilon - Tolerance
      Returns:
      true if values are approximately equal
    • approximately

      public static boolean approximately(double a, double b)
      Checks if a value is approximately equal to another (within 0.0001)
      Parameters:
      a - First value
      b - Second value
      Returns:
      true if values are approximately equal
    • map

      public static double map(double value, double inMin, double inMax, double outMin, double outMax)
      Maps a value from one range to another
      Parameters:
      value - The value to map
      inMin - Input range minimum
      inMax - Input range maximum
      outMin - Output range minimum
      outMax - Output range maximum
      Returns:
      Mapped value