Class Math


  • public class Math
    extends java.lang.Object
    • 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 Vector3Dd abs​(Vector3Dd 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 Vector3Df abs​(Vector3Df 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 Vector3Dd clamp​(Vector3Dd q, Vector3Dd min, Vector3Dd max)
      Clamps values of q with min and max

      static Q clampQ​(Q q, QPair 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 Quaterniond eaaToQuaternion​(EAAd eaa)
      Equivalent angle axis to quaternion conversion.

      static Quaternionf 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 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 EAAd quaternionToEAA​(Quaterniond quat)
      Quaternion to equivalent angle axis conversion.

      static EAAf quaternionToEAA​(Quaternionf 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​(QPair 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 Quaterniond ranQuaterniond()
      Returns a uniformly distributed random orientation.

      static Quaternionf ranQuaternionf()
      Returns a uniformly distributed random orientation.

      static Rotation3Dd ranRotation3Dd()
      Returns a uniformly distributed random orientation.

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

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


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

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


      static Transform3Df ranTransform3Df​(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​(Vector3Dd s)
      Constructs a 3x3 skew-symmetric matrix S\in so(3)
      static EigenMatrix3f skew​(Vector3Df s)
      Constructs a 3x3 skew-symmetric matrix S\in so(3)
      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 Rotation3Dd zyxToRotation3D​(double roll, double pitch, double 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,
                               QPair 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 Vector3Dd clamp​(Vector3Dd q,
                                      Vector3Dd min,
                                      Vector3Dd 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​(QPair 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 EAAd quaternionToEAA​(Quaterniond 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​(Quaternionf 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 Quaterniond eaaToQuaternion​(EAAd 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 Quaternionf 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 Rotation3Dd 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
      • skew

        public static EigenMatrix3d skew​(Vector3Dd s)
        Constructs a 3x3 skew-symmetric matrix S\in so(3)
        Parameters:
        s - [in] the s_x , s_y and s_z of the matrix
        Returns:
        The 3x3 skew-symmetric matrix S

        S = \left[ \begin{array}{ccc} 0 -s_z s_y\\ s_z 0 -s_x\\ -s_y s_x 0 \end{array} \right]
      • skew

        public static EigenMatrix3f skew​(Vector3Df s)
        Constructs a 3x3 skew-symmetric matrix S\in so(3)
        Parameters:
        s - [in] the s_x , s_y and s_z of the matrix
        Returns:
        The 3x3 skew-symmetric matrix S

        S = \left[ \begin{array}{ccc} 0 -s_z s_y\\ s_z 0 -s_x\\ -s_y s_x 0 \end{array} \right]
      • ranQuaterniond

        public static Quaterniond ranQuaterniond()
        Returns a uniformly distributed random orientation.

        Returns:
        Random orientation represented as a Quaternion
      • ranQuaternionf

        public static Quaternionf ranQuaternionf()
        Returns a uniformly distributed random orientation.

        Returns:
        Random orientation represented as a Quaternion
      • ranRotation3Dd

        public static Rotation3Dd ranRotation3Dd()
        Returns a uniformly distributed random orientation.

        Returns:
        Random orientation represented as a Rotation3D
      • ranRotation3Df

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

        Returns:
        Random orientation represented as a Rotation3D
      • ranTransform3Dd

        public static Transform3Dd ranTransform3Dd​(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
      • ranTransform3Dd

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


        Returns:
        Random Transform3D
      • ranTransform3Df

        public static Transform3Df ranTransform3Df​(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
      • ranTransform3Df

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


        Returns:
        Random Transform3D
      • abs

        public static Vector3Dd abs​(Vector3Dd 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)
      • abs

        public static Vector3Df abs​(Vector3Df 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)