Package org.chsrobotics.lib.math
Class UtilityMath
- java.lang.Object
-
- org.chsrobotics.lib.math.UtilityMath
-
public class UtilityMath extends java.lang.ObjectVarious useful small math functions.
-
-
Constructor Summary
Constructors Constructor Description UtilityMath()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doublenormalizeAngleDegrees(double angleDegrees)Normalizes an angle in degrees between 0 and 360.static doublenormalizeAngleRadians(double angleRadians)Normalizes an angle in radians between 0 and 2 pi.static double[]normalizeSet(double[] inputs, double maxAbsoluteValue)Scales a set of doubles symmetrically to ensure that none of them exceed a maximum absolute value, while still maintaining the same ratio.static double[]scaleToSum(double[] inputs, double desiredSum)Scales a set of doubles symmetrically such that they sum to a desired number, while maintaining the same ratio.static doublesimpleLinearInterpolation(double y0, double x0, double y1, double x1, double x)Interpolates a value between two points.static doublesmallestAngleDegreesBetween(double angleA, double angleB)Returns the angle in degrees between two other angles with the smallest absolute value.static doublesmallestAngleRadiansBetween(double angleA, double angleB)Returns the angle in radians between two other angles with the smallest absolute value.
-
-
-
Method Detail
-
normalizeAngleRadians
public static double normalizeAngleRadians(double angleRadians)
Normalizes an angle in radians between 0 and 2 pi.- Parameters:
angleRadians- Value in radians of the angle.- Returns:
- The normalized value.
-
normalizeAngleDegrees
public static double normalizeAngleDegrees(double angleDegrees)
Normalizes an angle in degrees between 0 and 360.- Parameters:
angleDegrees- Value of the angle.- Returns:
- The normalized value.
-
smallestAngleRadiansBetween
public static double smallestAngleRadiansBetween(double angleA, double angleB)Returns the angle in radians between two other angles with the smallest absolute value.A negative number indicates a clockwise rotation from angle a to angle b.
- Parameters:
angleA- The first angle, in radians.angleB- The second angle, in raidans.- Returns:
- A signed angle in radians representing the smallest (positive is counterclockwise) angle between angles a and b.
-
smallestAngleDegreesBetween
public static double smallestAngleDegreesBetween(double angleA, double angleB)Returns the angle in degrees between two other angles with the smallest absolute value.A negative number indicates a clockwise rotation from angle a to angle b.
- Parameters:
angleA- The first angle, in degrees.angleB- The second angle, in degrees.- Returns:
- A signed angle in degrees representing the smallest (positive is counterclockwise) angle between angles a and b.
-
simpleLinearInterpolation
public static double simpleLinearInterpolation(double y0, double x0, double y1, double x1, double x)Interpolates a value between two points.For more complex, multi-point interpolation, use the
MultiPointInterpolatorclass.- Parameters:
y0- The initial value of the dependent variable.x0- The initial value of the independent variable.y1- The final value of the dependent variable.x1- The final value of the independent variable.x- The place at which to sample for the returned value.- Returns:
- The linearly interpolated value.
-
scaleToSum
public static double[] scaleToSum(double[] inputs, double desiredSum)Scales a set of doubles symmetrically such that they sum to a desired number, while maintaining the same ratio.- Parameters:
inputs- An array of doubles. If empty, this will return an empty array.desiredSum- The desired sum, positive or negative, of the outputs. If equal to zero, this will return an array of zeros of length equal to the input's length.- Returns:
- An array of doubles with the same ratios between each other as the inputs.
-
normalizeSet
public static double[] normalizeSet(double[] inputs, double maxAbsoluteValue)Scales a set of doubles symmetrically to ensure that none of them exceed a maximum absolute value, while still maintaining the same ratio.- Parameters:
inputs- An array of the input values. If empty, this will return an empty array.maxAbsoluteValue- The maximum absolute value allowed for an output.- Returns:
- An array of the scaled values, in the same order as they were input.
-
-