us.ihmc.utilities.math
Class MathTools

java.lang.Object
  extended by us.ihmc.utilities.math.MathTools

public class MathTools
extends java.lang.Object


Method Summary
static void checkIfEqual(double val, double desired, double epsilon)
           
static void checkIfEqual(int val, int desired)
           
static void checkIfInRange(double argument, double min, double max)
           
static double clipToMinMax(double val, double min, double max)
          Returns max if max greater than given value Returns min if min less than given value Returns value if value is between max and min
static float clipToMinMax(float val, float min, float max)
           
static double cube(double x)
           
static double[] cumulativeSumDoubles(double[] doubles)
          Computes the cumulative sum array for a given array of doubles.
static java.util.ArrayList<FrameVector> diff(java.util.ArrayList<FrameVector> array)
           
static double[] diff(double[] array)
          Subtracts each element of a double array by the previous element in the array, returns the new array
static double[] dotPlus(double[] array, double addToAllElementsOfA)
          Adds parameter 'addToAllElements' to all elements of the double array and returns the new array
static int[] dotPlus(int[] array, int addToAllElementsOfA)
          Adds parameter 'addToAllElements' to all elements of the integer array and returns the new array
static boolean epsilonEquals(double v1, double v2, double epsilon)
          True if value |(v1-v2)| <= |epsilon| false if not
static double generateRandomDoubleInRange(java.util.Random random, double range1, double range2)
          Returns an evenly distributed random number between two bounds.
static double get(javax.vecmath.Tuple3d tuple, Direction direction)
           
static boolean isFinite(double proposed)
           
static boolean isFinite(javax.vecmath.Tuple3d tuple)
           
static boolean isGreaterThan(double value, double valueToCompareAgainst, int precision)
           
static boolean isGreaterThanOrEqualTo(double value, double valueToCompareAgainst, int precision)
           
static boolean isInsideBoundsExclusive(double val, double min, double max)
          Checks to see if val is Inside Bounds of max and min
static boolean isInsideBoundsInclusive(double val, double min, double max)
           
static boolean isLessThan(double value, double valueToCompareAgainst, int precision)
           
static boolean isLessThanOrEqualTo(double value, double valueToCompareAgainst, int precision)
           
static boolean isNumber(double proposed)
           
static double max(double[] array)
          Finds and returns the max value in an array of Doubles
static double mean(java.util.ArrayList<java.lang.Double> array)
           
static double mean(double[] array)
           
static double min(double[] array)
          Finds and returns the min value in an array of doubles
static void set(javax.vecmath.Tuple3d tuple, Direction direction, double value)
           
static double sign(double argument)
          Returns the sign of the argument.
static double square(double x)
           
static double sumDoubles(java.util.Collection<java.lang.Double> doubles)
          Sums the doubles in a collection
static double sumDoubles(double[] doubles)
          Finds the sum of doubles in an array
static int sumIntegers(java.util.Collection<java.lang.Integer> integers)
          Sums the integers in a collection
static int sumIntegers(int[] integers)
          Sums the integers in an array
static boolean withinPercentEquals(double v1, double v2, double percent)
          True if v2 is within given percent of v1 False otherwise
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

sign

public static double sign(double argument)
Returns the sign of the argument. 1.0 if positive or 0.0, -1.0 if negative. (Unlike Math.signum that returns 0.0 if the argument is 0.0)

Parameters:
argument - double
Returns:
double 1.0 if d >= 0.0, else -1.0

dotPlus

public static int[] dotPlus(int[] array,
                            int addToAllElementsOfA)
Adds parameter 'addToAllElements' to all elements of the integer array and returns the new array

Parameters:
array - int[]
addToAllElementsOfA - int
Returns:
int[]

dotPlus

public static double[] dotPlus(double[] array,
                               double addToAllElementsOfA)
Adds parameter 'addToAllElements' to all elements of the double array and returns the new array

Parameters:
array - double[]
addToAllElementsOfA - double
Returns:
double[]

diff

public static java.util.ArrayList<FrameVector> diff(java.util.ArrayList<FrameVector> array)
Parameters:
array - ArrayList
Returns:
ArrayList

diff

public static double[] diff(double[] array)
Subtracts each element of a double array by the previous element in the array, returns the new array

Parameters:
array - double[]
Returns:
double[]

generateRandomDoubleInRange

public static double generateRandomDoubleInRange(java.util.Random random,
                                                 double range1,
                                                 double range2)
Returns an evenly distributed random number between two bounds. The bounds do not need to be in min/max order.

Parameters:
random - Random number generator.
range - One side of the bounds.
range2 - Other side of the bounds.
Returns:
Random number between bounds1 and bounds2.

epsilonEquals

public static boolean epsilonEquals(double v1,
                                    double v2,
                                    double epsilon)
True if value |(v1-v2)| <= |epsilon| false if not

Parameters:
v1 - double
v2 - double
epsilon - double
Returns:
boolean

withinPercentEquals

public static boolean withinPercentEquals(double v1,
                                          double v2,
                                          double percent)
True if v2 is within given percent of v1 False otherwise

Parameters:
v1 - double
v2 - double
percent - double
Returns:
boolean

clipToMinMax

public static double clipToMinMax(double val,
                                  double min,
                                  double max)
Returns max if max greater than given value Returns min if min less than given value Returns value if value is between max and min

Parameters:
val - double
min - double
max - double
Returns:
double

clipToMinMax

public static float clipToMinMax(float val,
                                 float min,
                                 float max)

isInsideBoundsExclusive

public static boolean isInsideBoundsExclusive(double val,
                                              double min,
                                              double max)
Checks to see if val is Inside Bounds of max and min

Parameters:
val - double
min - double
max - double
Returns:
boolean

isInsideBoundsInclusive

public static boolean isInsideBoundsInclusive(double val,
                                              double min,
                                              double max)

sumIntegers

public static int sumIntegers(java.util.Collection<java.lang.Integer> integers)
Sums the integers in a collection

Parameters:
integers - collection of integers
Returns:
int the sum

sumIntegers

public static int sumIntegers(int[] integers)
Sums the integers in an array

Parameters:
integers - array of integers
Returns:
int the sum

sumDoubles

public static double sumDoubles(java.util.Collection<java.lang.Double> doubles)
Sums the doubles in a collection

Parameters:
doubles - collection of doubles
Returns:
double the sum

sumDoubles

public static double sumDoubles(double[] doubles)
Finds the sum of doubles in an array

Parameters:
array - double[] return double

cumulativeSumDoubles

public static double[] cumulativeSumDoubles(double[] doubles)
Computes the cumulative sum array for a given array of doubles. For example, the cumulative sum sequence of the input sequence {a, b, c, ...} is {a, a + b, a + b + c, ...}

Parameters:
doubles - input sequence
Returns:
cumulative sum sequence

min

public static double min(double[] array)
Finds and returns the min value in an array of doubles

Parameters:
array - double[]
Returns:
double

max

public static double max(double[] array)
Finds and returns the max value in an array of Doubles

Parameters:
array - double[]
Returns:
double

mean

public static double mean(double[] array)
Parameters:
array - double[]
Returns:
double

mean

public static double mean(java.util.ArrayList<java.lang.Double> array)
Parameters:
array - ArrayList
Returns:
double

checkIfInRange

public static void checkIfInRange(double argument,
                                  double min,
                                  double max)

square

public static double square(double x)

cube

public static double cube(double x)

checkIfEqual

public static void checkIfEqual(double val,
                                double desired,
                                double epsilon)

isGreaterThan

public static boolean isGreaterThan(double value,
                                    double valueToCompareAgainst,
                                    int precision)

isGreaterThanOrEqualTo

public static boolean isGreaterThanOrEqualTo(double value,
                                             double valueToCompareAgainst,
                                             int precision)

isLessThan

public static boolean isLessThan(double value,
                                 double valueToCompareAgainst,
                                 int precision)

isLessThanOrEqualTo

public static boolean isLessThanOrEqualTo(double value,
                                          double valueToCompareAgainst,
                                          int precision)

checkIfEqual

public static void checkIfEqual(int val,
                                int desired)

set

public static void set(javax.vecmath.Tuple3d tuple,
                       Direction direction,
                       double value)

get

public static double get(javax.vecmath.Tuple3d tuple,
                         Direction direction)

isFinite

public static boolean isFinite(double proposed)

isNumber

public static boolean isNumber(double proposed)

isFinite

public static boolean isFinite(javax.vecmath.Tuple3d tuple)