Package de.eldoria.eldoutilities.utils
Class EMath
java.lang.Object
de.eldoria.eldoutilities.utils.EMath
Utility class with basic math functions which are not covered by java.math
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
clamp
(double min, double max, double value) Clamp a value.static float
clamp
(float min, float max, float value) Clamp a value.static int
clamp
(int min, int max, int value) Clamp a value.static long
clamp
(long min, long max, long value) Clamp a value.compareValues
(double a, double b) Compare two valuescompareValues
(float a, float b) Compare two valuescompareValues
(int a, int b) Compare two valuesstatic double
diff
(double a, double b) Returns the total difference between two numbersstatic float
diff
(float a, float b) Returns the total difference between two numbersstatic int
diff
(int a, int b) Returns the total difference between two numbersstatic double
parabolaValue
(double xVector, double yVector, double xPoint, double yPoint, double x) Method to get a point from a parabola.static double
smoothCurveValue
(double x) Returns a smooth curve created with two opposite parabolas.static double
Returns a smooth curve created with two opposite parabolas.
-
Method Details
-
clamp
public static int clamp(int min, int max, int value) Clamp a value.- Parameters:
min
- min valuemax
- max valuevalue
- value to clamp- Returns:
- value with a size between min and max
-
clamp
public static float clamp(float min, float max, float value) Clamp a value.- Parameters:
min
- min valuemax
- max valuevalue
- value to clamp- Returns:
- value with a size between min and max
-
clamp
public static long clamp(long min, long max, long value) Clamp a value.- Parameters:
min
- min valuemax
- max valuevalue
- value to clamp- Returns:
- value with a size between min and max
-
clamp
public static double clamp(double min, double max, double value) Clamp a value.- Parameters:
min
- min valuemax
- max valuevalue
- value to clamp- Returns:
- value with a size between min and max
-
diff
public static float diff(float a, float b) Returns the total difference between two numbers- Parameters:
a
- first valueb
- second value- Returns:
- the total difference between two numbers
-
diff
public static double diff(double a, double b) Returns the total difference between two numbers- Parameters:
a
- first valueb
- second value- Returns:
- the total difference between two numbers
-
diff
public static int diff(int a, int b) Returns the total difference between two numbers- Parameters:
a
- first valueb
- second value- Returns:
- the total difference between two numbers
-
compareValues
Compare two values- Parameters:
a
- first valueb
- second value- Returns:
- Pair of values. smaller value is first.
-
compareValues
Compare two values- Parameters:
a
- first valueb
- second value- Returns:
- Pair of values. smaller value is first.
-
compareValues
Compare two values- Parameters:
a
- first valueb
- second value- Returns:
- Pair of values. smaller value is first.
-
parabolaValue
public static double parabolaValue(double xVector, double yVector, double xPoint, double yPoint, double x) Method to get a point from a parabola.Creates a parabola from a point and the vertex of a parabola.
- Parameters:
xVector
- X Value of the VectoryVector
- Y Value of the VectorxPoint
- x Value of the PointyPoint
- Y Value of the Pointx
- The Value of x in f(x);- Returns:
- Returns the value of f(x) at the specified point.
-
smoothCurveValue
public static double smoothCurveValue(double x) Returns a smooth curve created with two opposite parabolas.The slope at the start and end is 0.
The curve is generated by a start and endpoint.
The x value of the start point must be smaller than the end point
Returns always a value between half of the height and 0;
- Parameters:
x
- The Point x between the start and end point.- Returns:
- Returns a value between 0 and 1.
-
smoothCurveValue
Returns a smooth curve created with two opposite parabolas.The slope at the start and end is 0.
The curve is generated by a start and endpoint.
The x value of the start point must be smaller than the end point
- Parameters:
start
- The start point as a tuple of two floatsend
- The end point as a tuple of two floatsx
- The Point x between the start end end point.- Returns:
- Returns a float which contains the value of the curve at the point x
-