Class Math


  • public class Math
    extends java.lang.Object
    Utility functions for the rw::math module.
    • Constructor Summary

      Constructors 
      Constructor Description
      Math​(long cPtr, boolean cMemoryOwn)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Q abs​(Q v)
      Returns vector with the absolute values

      Given a vector v=[v_1,v_2,\ldots,v_n] then Abs(v) is defined as
      Abs(v)=[abs(v_1),abs(v_i),\ldots,abs(v_n)]

      static int ceilLog2​(int n)
      Exact implementation of ceil(log_2(n)) for n > 0.
      static double clamp​(double val, double min, double max)
      clamp val to either min or max

      static Vector3D clamp​(Vector3D q, Vector3D min, Vector3D max)
      Clamps values of q with min and max

      static Q clampQ​(Q q, PairQ bounds)
      Clamps values of q with bounds.first and bounds.second

      static Q clampQ​(Q q, Q min, Q max)
      Clamps values of q with min and max

      void delete()  
      static Quaternion eaaToQuaternion​(EAA eaa)
      Equivalent angle axis to quaternion conversion.

      static Quaternion_f eaaToQuaternion​(EAAf eaa)
      Equivalent angle axis to quaternion conversion.

      static long factorial​(long n)
      Factorial
      The method does not implement any safe guards for negative numbers of overflow of
      numbers.
      static Rotation3Df fromStdVectorToMat​(vector_d data, Rotation3Df tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static Rotation3D fromStdVectorToMat​(vector_d data, Rotation3D tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static Transform3Df fromStdVectorToMat​(vector_d data, Transform3Df tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static Transform3D fromStdVectorToMat​(vector_d data, Transform3D tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static Rotation3Df fromStdVectorToMat_f​(vector_f data, Rotation3Df tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static Rotation3D fromStdVectorToMat_f​(vector_f data, Rotation3D tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static Transform3Df fromStdVectorToMat_f​(vector_f data, Transform3Df tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static Transform3D fromStdVectorToMat_f​(vector_f data, Transform3D tmp, int size1, int size2)
      convert a vector of doubles to a matrix math type.
      static long getCPtr​(Math obj)  
      static boolean isNaN​(double d)
      Implements an isNaN function

      Use to make sure code is independent of specific compile specific implementations
      static double max​(Q v)
      Returns the largest element of v

      If the vector has zero length, the method returns 0

      static double min​(Q v)
      Returns the smallest element of v

      If the vector has zero length, the method returns 0

      static double NaN()
      Get a value for NaN.

      Use to make sure code is independent of specific compile specific implementations

      static EAA quaternionToEAA​(Quaternion quat)
      Quaternion to equivalent angle axis conversion.

      static EAAf quaternionToEAA​(Quaternion_f quat)
      Quaternion to equivalent angle axis conversion.

      static double ran()
      A random double in the range [0, 1[ using a uniform distribution.

      Note: Uses boost::random
      static double ran​(double from, double to)
      A random double in the range [from, to[ using a uniform distribution.

      Note: Uses boost::random
      static Q ranDir​(long dim)
      Returns a random direction in dim dimensions using the standard normal
      distribution.

      The length of the vector is given by length;

      static Q ranDir​(long dim, double length)
      Returns a random direction in dim dimensions using the standard normal
      distribution.

      The length of the vector is given by length;

      static int ranI​(int from, int to)
      A random integer in the range [from, to[ using a uniform distribution.

      Note: Uses boost::random
      static double ranNormalDist​(double mean, double sigma)
      Returns a random sample around mean with standard deviation sigma using the
      normal distribution.

      Note: Uses boost::random
      Warning: The number sequence generated can vary in different Boost versions (there is a
      known change in Boost 1.56.0).

      static Q ranQ​(PairQ bounds)
      Returns a random Q between with values in the range [bounds.first, bounds.second[
      using a uniform distribution.

      Note: Uses boost::random

      static Q ranQ​(Q from, Q to)
      Returns a random Q between with values in the range [from, to[ using a uniform
      distribution.

      Note: Uses boost::random

      static Quaternion ranQuaternion()
      Returns a uniformly distributed random orientation.

      static Quaternion_f ranQuaternion_f()
      Returns a uniformly distributed random orientation.

      static Rotation3D ranRotation3D()
      Returns a uniformly distributed random orientation.

      static Rotation3Df ranRotation3D_f()
      Returns a uniformly distributed random orientation.

      static Transform3D ranTransform3D()
      Returns random Transform3D based on ranDir (using the standard normal
      distribution) and ranRotation3D (using a uniform distribution).


      static Transform3D ranTransform3D​(double translationLength)
      Returns random Transform3D based on ranDir (using the standard normal
      distribution) and ranRotation3D (using a uniform distribution).

      static Transform3Df ranTransform3D_f()
      Returns random Transform3D based on ranDir (using the standard normal
      distribution) and ranRotation3D (using a uniform distribution).


      static Transform3Df ranTransform3D_f​(double translationLength)
      Returns random Transform3D based on ranDir (using the standard normal
      distribution) and ranRotation3D (using a uniform distribution).

      static Q ranWeightedDir​(long dim, Q weights)
      Returns a weighted random direction in dim dimensions using the standard normal
      distribution.

      The length of the vector is given by length;

      static Q ranWeightedDir​(long dim, Q weights, double length)
      Returns a weighted random direction in dim dimensions using the standard normal
      distribution.

      The length of the vector is given by length;

      static double round​(double d)
      Rounds off to nearest integer

      With some compilers round can be found in math.h.
      static void seed()
      Seeds the random number generator with current time of day

      Note: Uses boost::random
      static void seed​(long seed)
      Seeds the random number generator.

      Note: Uses boost::random
      static double sign​(double s)
      Returns the sign of s

      If s < 0 it return 0.
      static Q sign​(Q q)
      Returns the sign of each element

      For each element either -1 or 1 is returned depending on the sign.
      static EigenMatrix3d skew​(Vector3D s)  
      static EigenMatrix3f skew​(Vector3Df s)  
      static Q sqr​(Q q)
      The squares of the elements of q.
      static Q sqrt​(Q q)
      The square roots of the elements of q.
      static vector_d toStdVector​(Rotation3Df tmp, int size1, int size2)  
      static vector_d toStdVector​(Rotation3D tmp, int size1, int size2)  
      static vector_d toStdVector​(Transform3Df tmp, int size1, int size2)  
      static vector_d toStdVector​(Transform3D tmp, int size1, int size2)  
      static vector_d toStdVector​(Vector3Df tmp, int size)  
      static vector_d toStdVector​(Vector3D tmp, int size)  
      static Rotation3D zyxToRotation3D​(double roll, double pitch, double yaw)
      this function converts a EAA object to a Quaternion

      static Rotation3Df zyxToRotation3D​(float roll, float pitch, float yaw)
      this function converts a EAA object to a Quaternion

      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Math

        public Math​(long cPtr,
                    boolean cMemoryOwn)
    • Method Detail

      • getCPtr

        public static long getCPtr​(Math obj)
      • delete

        public void delete()
      • clamp

        public static double clamp​(double val,
                                   double min,
                                   double max)
        clamp val to either min or max

        Parameters:
        val - [in] the value that is to be clamped
        min - [in] the minimum allowed value
        max - [in] the maximum allowed value
        Returns:
        the clamped value of val
      • clampQ

        public static Q clampQ​(Q q,
                               Q min,
                               Q max)
        Clamps values of q with min and max

        Parameters:
        q - [in] Values to clamp
        min - [min] The minimum value
        max - [min] The maximum value
        Returns:
        The clamped values
      • clampQ

        public static Q clampQ​(Q q,
                               PairQ bounds)
        Clamps values of q with bounds.first and bounds.second

        Parameters:
        q - [in] Values to clamp
        bounds - [min] The pair containing minimum and maximum values as first and second
        element
        Returns:
        The clamped values
      • clamp

        public static Vector3D clamp​(Vector3D q,
                                     Vector3D min,
                                     Vector3D max)
        Clamps values of q with min and max

        Parameters:
        q - [in] Values to clamp
        min - [min] The minimum value
        max - [min] The maximum value
        Returns:
        The clamped values
      • ran

        public static double ran()
        A random double in the range [0, 1[ using a uniform distribution.

        Note: Uses boost::random
      • seed

        public static void seed​(long seed)
        Seeds the random number generator.

        Note: Uses boost::random
      • seed

        public static void seed()
        Seeds the random number generator with current time of day

        Note: Uses boost::random
      • ran

        public static double ran​(double from,
                                 double to)
        A random double in the range [from, to[ using a uniform distribution.

        Note: Uses boost::random
      • ranI

        public static int ranI​(int from,
                               int to)
        A random integer in the range [from, to[ using a uniform distribution.

        Note: Uses boost::random
      • ranNormalDist

        public static double ranNormalDist​(double mean,
                                           double sigma)
        Returns a random sample around mean with standard deviation sigma using the
        normal distribution.

        Note: Uses boost::random
        Warning: The number sequence generated can vary in different Boost versions (there is a
        known change in Boost 1.56.0).

        Parameters:
        mean - [in] Means value
        sigma - [in] Standard deviation
        Returns:
        Random sample
      • ranQ

        public static Q ranQ​(Q from,
                             Q to)
        Returns a random Q between with values in the range [from, to[ using a uniform
        distribution.

        Note: Uses boost::random

        Parameters:
        from - [in] The lower bound
        to - [in] The upper bound
        Returns:
        Random Q
      • ranQ

        public static Q ranQ​(PairQ bounds)
        Returns a random Q between with values in the range [bounds.first, bounds.second[
        using a uniform distribution.

        Note: Uses boost::random

        Parameters:
        bounds - [in] The lower and upper bounds
        Returns:
        Random Q
      • ranDir

        public static Q ranDir​(long dim,
                               double length)
        Returns a random direction in dim dimensions using the standard normal
        distribution.

        The length of the vector is given by length;

        Parameters:
        dim - [in] Number of dimensions
        length - [in] Length of return vector. Default is 1;
        Returns:
        Random direction

        Warning: Please see the warning for Math::ranNormalDist
      • ranDir

        public static Q ranDir​(long dim)
        Returns a random direction in dim dimensions using the standard normal
        distribution.

        The length of the vector is given by length;

        Parameters:
        dim - [in] Number of dimensions

        Returns:
        Random direction

        Warning: Please see the warning for Math::ranNormalDist
      • ranWeightedDir

        public static Q ranWeightedDir​(long dim,
                                       Q weights,
                                       double length)
        Returns a weighted random direction in dim dimensions using the standard normal
        distribution.

        The length of the vector is given by length;

        Parameters:
        dim - [in] Number of dimensions
        weights - [in] Weights to use
        length - [in] Length of return vector when weights are applied as weighted Euclidean
        metric. Default is 1;
        Returns:
        Random weigthed direction

        Warning: Please see the warning for Math::ranNormalDist
      • ranWeightedDir

        public static Q ranWeightedDir​(long dim,
                                       Q weights)
        Returns a weighted random direction in dim dimensions using the standard normal
        distribution.

        The length of the vector is given by length;

        Parameters:
        dim - [in] Number of dimensions
        weights - [in] Weights to use

        Returns:
        Random weigthed direction

        Warning: Please see the warning for Math::ranNormalDist
      • round

        public static double round​(double d)
        Rounds off to nearest integer

        With some compilers round can be found in math.h. This however does not
        appear to be ansi C/C++ standard

        Parameters:
        d - [in] number to round
        Returns:
        d rounded to nearest integer.
      • sqr

        public static Q sqr​(Q q)
        The squares of the elements of q.
      • sqrt

        public static Q sqrt​(Q q)
        The square roots of the elements of q.
      • abs

        public static Q abs​(Q v)
        Returns vector with the absolute values

        Given a vector v=[v_1,v_2,\ldots,v_n] then Abs(v) is defined as
        Abs(v)=[abs(v_1),abs(v_i),\ldots,abs(v_n)]

        Parameters:
        v - [in] the vector v
        Returns:
        the vector Abs(v)
      • min

        public static double min​(Q v)
        Returns the smallest element of v

        If the vector has zero length, the method returns 0

        Parameters:
        v - [in] the vector v
        Returns:
        the smallest element
      • max

        public static double max​(Q v)
        Returns the largest element of v

        If the vector has zero length, the method returns 0

        Parameters:
        v - [in] the vector v
        Returns:
        the largest element
      • sign

        public static double sign​(double s)
        Returns the sign of s

        If s < 0 it return 0. If s >= 0 then 1 is returned.

        Parameters:
        s - [in] The value for which to return the sign
        Returns:
        The sign
      • sign

        public static Q sign​(Q q)
        Returns the sign of each element

        For each element either -1 or 1 is returned depending on the sign. If q(i) equals 0
        the method returns 1

        Parameters:
        q - [in] Vector for which to get the signs
        Returns:
        Vector of sign values
      • ceilLog2

        public static int ceilLog2​(int n)
        Exact implementation of ceil(log_2(n)) for n > 0.
      • factorial

        public static long factorial​(long n)
        Factorial
        The method does not implement any safe guards for negative numbers of overflow of
        numbers.
      • isNaN

        public static boolean isNaN​(double d)
        Implements an isNaN function

        Use to make sure code is independent of specific compile specific implementations
      • NaN

        public static double NaN()
        Get a value for NaN.

        Use to make sure code is independent of specific compile specific implementations

        Returns:
        a double representation of NaN.
      • quaternionToEAA

        public static EAA quaternionToEAA​(Quaternion quat)
        Quaternion to equivalent angle axis conversion.

        Parameters:
        quat - [in] the Quaternion object that is to be converted.

        Returns:
        a EAA object that represents the converted quaternion
      • quaternionToEAA

        public static EAAf quaternionToEAA​(Quaternion_f quat)
        Quaternion to equivalent angle axis conversion.

        Parameters:
        quat - [in] the Quaternion object that is to be converted.

        Returns:
        a EAA object that represents the converted quaternion
      • eaaToQuaternion

        public static Quaternion eaaToQuaternion​(EAA eaa)
        Equivalent angle axis to quaternion conversion.

        Parameters:
        eaa - [in] the EAA object that is to be converted

        Returns:
        a Quaternion object that represents the converted EAA
      • eaaToQuaternion

        public static Quaternion_f eaaToQuaternion​(EAAf eaa)
        Equivalent angle axis to quaternion conversion.

        Parameters:
        eaa - [in] the EAA object that is to be converted

        Returns:
        a Quaternion object that represents the converted EAA
      • zyxToRotation3D

        public static Rotation3D zyxToRotation3D​(double roll,
                                                 double pitch,
                                                 double yaw)
        this function converts a EAA object to a Quaternion

        Parameters:
        roll - [in] rotation around z
        pitch - [in] rotation around y
        yaw - [in] rotation around x

        Returns:
        a Quaternion object that represents the converted EAA
      • zyxToRotation3D

        public static Rotation3Df zyxToRotation3D​(float roll,
                                                  float pitch,
                                                  float yaw)
        this function converts a EAA object to a Quaternion

        Parameters:
        roll - [in] rotation around z
        pitch - [in] rotation around y
        yaw - [in] rotation around x

        Returns:
        a Quaternion object that represents the converted EAA
      • ranQuaternion

        public static Quaternion ranQuaternion()
        Returns a uniformly distributed random orientation.

        Returns:
        Random orientation represented as a Quaternion
      • ranTransform3D

        public static Transform3D ranTransform3D​(double translationLength)
        Returns random Transform3D based on ranDir (using the standard normal
        distribution) and ranRotation3D (using a uniform distribution).

        Parameters:
        translationLength - [in]
        Returns:
        Random Transform3D
      • ranTransform3D

        public static Transform3D ranTransform3D()
        Returns random Transform3D based on ranDir (using the standard normal
        distribution) and ranRotation3D (using a uniform distribution).


        Returns:
        Random Transform3D
      • ranRotation3D

        public static Rotation3D ranRotation3D()
        Returns a uniformly distributed random orientation.

        Returns:
        Random orientation represented as a Rotation3D
      • ranQuaternion_f

        public static Quaternion_f ranQuaternion_f()
        Returns a uniformly distributed random orientation.

        Returns:
        Random orientation represented as a Quaternion
      • ranTransform3D_f

        public static Transform3Df ranTransform3D_f​(double translationLength)
        Returns random Transform3D based on ranDir (using the standard normal
        distribution) and ranRotation3D (using a uniform distribution).

        Parameters:
        translationLength - [in]
        Returns:
        Random Transform3D
      • ranTransform3D_f

        public static Transform3Df ranTransform3D_f()
        Returns random Transform3D based on ranDir (using the standard normal
        distribution) and ranRotation3D (using a uniform distribution).


        Returns:
        Random Transform3D
      • ranRotation3D_f

        public static Rotation3Df ranRotation3D_f()
        Returns a uniformly distributed random orientation.

        Returns:
        Random orientation represented as a Rotation3D
      • fromStdVectorToMat

        public static Transform3D fromStdVectorToMat​(vector_d data,
                                                     Transform3D tmp,
                                                     int size1,
                                                     int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • fromStdVectorToMat

        public static Transform3Df fromStdVectorToMat​(vector_d data,
                                                      Transform3Df tmp,
                                                      int size1,
                                                      int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • fromStdVectorToMat_f

        public static Transform3D fromStdVectorToMat_f​(vector_f data,
                                                       Transform3D tmp,
                                                       int size1,
                                                       int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • fromStdVectorToMat_f

        public static Transform3Df fromStdVectorToMat_f​(vector_f data,
                                                        Transform3Df tmp,
                                                        int size1,
                                                        int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • fromStdVectorToMat

        public static Rotation3D fromStdVectorToMat​(vector_d data,
                                                    Rotation3D tmp,
                                                    int size1,
                                                    int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • fromStdVectorToMat

        public static Rotation3Df fromStdVectorToMat​(vector_d data,
                                                     Rotation3Df tmp,
                                                     int size1,
                                                     int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • fromStdVectorToMat_f

        public static Rotation3D fromStdVectorToMat_f​(vector_f data,
                                                      Rotation3D tmp,
                                                      int size1,
                                                      int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • fromStdVectorToMat_f

        public static Rotation3Df fromStdVectorToMat_f​(vector_f data,
                                                       Rotation3Df tmp,
                                                       int size1,
                                                       int size2)
        convert a vector of doubles to a matrix math type. The math type should implement
        the operator (i,j) in order to use this function.
        Parameters:
        data - [in] the input
        tmp - [out] the output
        size1 - [in] the size of the first dimension of the matrix.
        size2 - [in] the size of the second dimension of the matrix.
        Returns:
        reference to tmp
      • toStdVector

        public static vector_d toStdVector​(Transform3D tmp,
                                           int size1,
                                           int size2)
      • toStdVector

        public static vector_d toStdVector​(Rotation3D tmp,
                                           int size1,
                                           int size2)
      • toStdVector

        public static vector_d toStdVector​(Rotation3Df tmp,
                                           int size1,
                                           int size2)