Class MathUtils
java.lang.Object
ActiverseUtils.MathUtils
MathUtils - Common mathematical utility functions for game development
- Version:
- 1.4.1
- Author:
- Knivier
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleangleBetween(double x1, double y1, double x2, double y2) Calculates angle between two points in radiansstatic booleanapproximately(double a, double b) Checks if a value is approximately equal to another (within 0.0001)static booleanapproximately(double a, double b, double epsilon) Checks if a value is approximately equal to another (within epsilon)static doubleclamp(double value, double min, double max) Clamps a value between a minimum and maximumstatic floatclamp(float value, float min, float max) Clamps a float value between a minimum and maximumstatic intclamp(int value, int min, int max) Clamps an integer value between a minimum and maximumstatic doubledistance(double x1, double y1, double x2, double y2) Calculates distance between two pointsstatic doublelerp(double start, double end, double t) Linear interpolation between two valuesstatic doublemap(double value, double inMin, double inMax, double outMin, double outMax) Maps a value from one range to anotherstatic doublenormalizeAngle(double angle) Normalizes an angle to be within 0 to 2π radiansstatic doubletoDegrees(double radians) Converts radians to degreesstatic doubletoRadians(double degrees) Converts degrees to radians
-
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 valueend- Ending valuet- 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 clampmin- Minimum valuemax- 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 clampmin- Minimum valuemax- 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 clampmin- Minimum valuemax- 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 Xy1- First point Yx2- Second point Xy2- 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 Xy1- First point Yx2- Second point Xy2- 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 valueb- Second valueepsilon- 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 valueb- 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 mapinMin- Input range minimuminMax- Input range maximumoutMin- Output range minimumoutMax- Output range maximum- Returns:
- Mapped value
-