RobWorkProject  6.6.6
Static Public Member Functions | List of all members
Math Class Reference

Utility functions for the rw::math module. More...

#include <Math.hpp>

Static Public Member Functions

template<class A >
static EAA< A > quaternionToEAA (const Quaternion< A > &quat)
 Quaternion to equivalent angle axis conversion. More...
 
template<class A >
static Quaternion< A > eaaToQuaternion (const EAA< A > &eaa)
 Equivalent angle axis to quaternion conversion. More...
 
template<class A >
static Rotation3D< A > zyxToRotation3D (A roll, A pitch, A yaw)
 this function converts a EAA object to a Quaternion More...
 
template<class R >
static boost::numeric::ublas::bounded_matrix< R, 3, 3 > skew (const boost::numeric::ublas::bounded_vector< R, 3 > &s)
 Constructs a 3x3 skew-symmetric matrix $ S\in so(3)$. More...
 
template<class R >
static Eigen::Matrix< R, 3, 3 > skew (const Vector3D< R > &s)
 Constructs a 3x3 skew-symmetric matrix $ S\in so(3)$. More...
 
static double clamp (double val, double min, double max)
 clamp val to either min or max More...
 
static rw::math::Q clampQ (const rw::math::Q &q, const rw::math::Q &min, const rw::math::Q &max)
 Clamps values of q with min and max. More...
 
static rw::math::Q clampQ (const rw::math::Q &q, const std::pair< rw::math::Q, rw::math::Q > &bounds)
 Clamps values of q with bounds.first and bounds.second. More...
 
static rw::math::Vector3D clamp (const rw::math::Vector3D<> &q, const rw::math::Vector3D<> &min, const rw::math::Vector3D<> &max)
 Clamps values of q with min and max. More...
 
static double ran ()
 A random double in the range [0, 1[ using a uniform distribution. More...
 
static void seed (unsigned seed)
 Seeds the random number generator. More...
 
static void seed ()
 Seeds the random number generator with current time of day. More...
 
static double ran (double from, double to)
 A random double in the range [from, to[ using a uniform distribution. More...
 
static int ranI (int from, int to)
 A random integer in the range [from, to[ using a uniform distribution. More...
 
static double ranNormalDist (double mean, double sigma)
 Returns a random sample around mean with standard deviation sigma using the normal distribution. More...
 
static rw::math::Q ranQ (const rw::math::Q &from, const rw::math::Q &to)
 Returns a random Q between with values in the range [from, to[ using a uniform distribution. More...
 
static rw::math::Q ranQ (const std::pair< rw::math::Q, rw::math::Q > &bounds)
 Returns a random Q between with values in the range [bounds.first, bounds.second[ using a uniform distribution. More...
 
static rw::math::Q ranDir (size_t dim, double length=1)
 Returns a random direction in dim dimensions using the standard normal distribution. More...
 
static rw::math::Q ranWeightedDir (size_t dim, const rw::math::Q &weights, double length=1)
 Returns a weighted random direction in dim dimensions using the standard normal distribution. More...
 
template<class T >
static rw::math::Quaternion< T > ranQuaternion ()
 Returns a uniformly distributed random orientation. More...
 
template<class T >
static rw::math::Rotation3D< T > ranRotation3D ()
 Returns a uniformly distributed random orientation. More...
 
template<class T >
static rw::math::Transform3D< T > ranTransform3D (const double translationLength=1)
 Returns random Transform3D based on ranDir (using the standard normal distribution) and ranRotation3D (using a uniform distribution). More...
 
static double round (double d)
 Rounds off to nearest integer. More...
 
template<class T >
static T sqr (const T &d)
 The square of d. More...
 
static Q sqr (const Q &q)
 The squares of the elements of q.
 
static Q sqrt (const Q &q)
 The square roots of the elements of q.
 
template<class T >
static boost::numeric::ublas::vector< T > abs (const boost::numeric::ublas::vector< T > &v)
 Returns vector with the absolute values. More...
 
static Q abs (const Q &v)
 Returns vector with the absolute values. More...
 
template<class T >
static T min (const boost::numeric::ublas::vector< T > &v)
 Returns the smallest element of v. More...
 
template<class T >
static T max (const boost::numeric::ublas::vector< T > &v)
 Returns the largest element of v. More...
 
static double min (const Q &v)
 Returns the smallest element of v. More...
 
static double max (const Q &v)
 Returns the largest element of v. More...
 
template<class T >
static T min (const T &a, const T &b)
 Returns vector with the elementwise smallest elements of a and b. More...
 
template<class T >
static T max (const T &a, const T &b)
 Returns vector with the elementwise largest elements of a and b. More...
 
template<class T >
static Vector3D< T > abs (const Vector3D< T > &v)
 Returns vector with the absolute values. More...
 
template<class T >
static T min (const Vector3D< T > &v)
 Returns the smallest element of v. More...
 
template<class T >
static T max (const Vector3D< T > &v)
 Returns the largest element of v. More...
 
template<class T >
static Vector3D< T > min (const Vector3D< T > &a, const Vector3D< T > &b)
 Returns vector with the elementwise smallest elements of a and b. More...
 
template<class T >
static Vector3D< T > max (const Vector3D< T > &a, const Vector3D< T > &b)
 Returns vector with the elementwise largest elements of a and b. More...
 
static double sign (double s)
 Returns the sign of s. More...
 
static Q sign (const Q &q)
 Returns the sign of each element. More...
 
static int ceilLog2 (int n)
 Exact implementation of ceil(log_2(n)) for n > 0.
 
static long long factorial (long long n)
 Factorial The method does not implement any safe guards for negative numbers of overflow of numbers.
 
template<class ARR >
static std::vector< double > toStdVector (const ARR &tmp, int size)
 convert a math vector type to an vector of doubles. The input should have the index operator () in order to use this conversion More...
 
template<class MAT >
static std::vector< double > toStdVector (const MAT &tmp, int size1, int size2)
 convert a math matrix type to an vector of doubles. The input should have the index operator (x,y) in order to use this conversion More...
 
template<class T , class ARR >
static ARR fromStdVector (const std::vector< T > &data, ARR &tmp)
 
template<class T , class MAT >
static MAT fromStdVectorToMat (const std::vector< T > &data, MAT &tmp, int size1, int size2)
 
static bool isNaN (double d)
 Implements an isNaN function. More...
 
static double NaN ()
 Get a value for NaN. More...
 

Detailed Description

Utility functions for the rw::math module.

Member Function Documentation

◆ abs() [1/3]

static boost::numeric::ublas::vector<T> abs ( const boost::numeric::ublas::vector< T > &  v)
inlinestatic

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() [2/3]

static Q abs ( const Q v)
inlinestatic

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() [3/3]

static Vector3D<T> abs ( const Vector3D< T > &  v)
inlinestatic

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)$

◆ clamp() [1/2]

static double clamp ( double  val,
double  min,
double  max 
)
inlinestatic

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

◆ clamp() [2/2]

static rw::math::Vector3D clamp ( const rw::math::Vector3D<> &  q,
const rw::math::Vector3D<> &  min,
const rw::math::Vector3D<> &  max 
)
inlinestatic

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() [1/2]

static rw::math::Q clampQ ( const rw::math::Q q,
const rw::math::Q min,
const rw::math::Q max 
)
inlinestatic

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() [2/2]

static rw::math::Q clampQ ( const rw::math::Q q,
const std::pair< rw::math::Q, rw::math::Q > &  bounds 
)
inlinestatic

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

◆ eaaToQuaternion()

static Quaternion<A> eaaToQuaternion ( const EAA< A > &  eaa)
inlinestatic

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

◆ fromStdVector()

static ARR fromStdVector ( const std::vector< T > &  data,
ARR &  tmp 
)
inlinestatic

convert a vector of doubles to a vector math type. The math type should implement the operator () in order to use this function.

Parameters
data[in] the input
tmp[out] the output
Returns
reference to tmp

◆ fromStdVectorToMat()

static MAT fromStdVectorToMat ( const std::vector< T > &  data,
MAT &  tmp,
int  size1,
int  size2 
)
inlinestatic

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

◆ isNaN()

static bool isNaN ( double  d)
static

Implements an isNaN function.

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

◆ max() [1/5]

static T max ( const boost::numeric::ublas::vector< T > &  v)
inlinestatic

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

◆ max() [2/5]

static double max ( const Q v)
inlinestatic

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

◆ max() [3/5]

static T max ( const T &  a,
const T &  b 
)
inlinestatic

Returns vector with the elementwise largest elements of a and b.

Parameters
a[in] the vector a
b[in] the vector b
Returns
Q with largest elements

◆ max() [4/5]

static T max ( const Vector3D< T > &  v)
inlinestatic

Returns the largest element of v.

Parameters
v[in] the vector v
Returns
the largest element

◆ max() [5/5]

static Vector3D<T> max ( const Vector3D< T > &  a,
const Vector3D< T > &  b 
)
inlinestatic

Returns vector with the elementwise largest elements of a and b.

Parameters
a[in] the vector a
b[in] the vector b
Returns
Vector with largest elements

◆ min() [1/5]

static T min ( const boost::numeric::ublas::vector< T > &  v)
inlinestatic

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

◆ min() [2/5]

static double min ( const Q v)
inlinestatic

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

◆ min() [3/5]

static T min ( const T &  a,
const T &  b 
)
inlinestatic

Returns vector with the elementwise smallest elements of a and b.

Parameters
a[in] the vector a
b[in] the vector b
Returns
Q with smallest elements

◆ min() [4/5]

static T min ( const Vector3D< T > &  v)
inlinestatic

Returns the smallest element of v.

Parameters
v[in] the vector v
Returns
the smallest element

◆ min() [5/5]

static Vector3D<T> min ( const Vector3D< T > &  a,
const Vector3D< T > &  b 
)
inlinestatic

Returns vector with the elementwise smallest elements of a and b.

Parameters
a[in] the vector a
b[in] the vector b
Returns
Vector with smallest elements

◆ NaN()

static double NaN ( )
static

Get a value for NaN.

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

Returns
a double representation of NaN.

◆ quaternionToEAA()

static EAA<A> quaternionToEAA ( const Quaternion< A > &  quat)
inlinestatic

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

◆ ran() [1/2]

static double ran ( )
static

A random double in the range [0, 1[ using a uniform distribution.

Note
Uses boost::random

◆ ran() [2/2]

static double ran ( double  from,
double  to 
)
static

A random double in the range [from, to[ using a uniform distribution.

Note
Uses boost::random

◆ ranDir()

static rw::math::Q ranDir ( size_t  dim,
double  length = 1 
)
static

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

◆ ranI()

static int ranI ( int  from,
int  to 
)
static

A random integer in the range [from, to[ using a uniform distribution.

Note
Uses boost::random

◆ ranNormalDist()

static double ranNormalDist ( double  mean,
double  sigma 
)
static

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() [1/2]

static rw::math::Q ranQ ( const rw::math::Q from,
const rw::math::Q to 
)
static

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() [2/2]

static rw::math::Q ranQ ( const std::pair< rw::math::Q, rw::math::Q > &  bounds)
static

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

◆ ranQuaternion()

static rw::math::Quaternion<T> ranQuaternion ( )
inlinestatic

Returns a uniformly distributed random orientation.

Returns
Random orientation represented as a Quaternion

◆ ranRotation3D()

static rw::math::Rotation3D<T> ranRotation3D ( )
inlinestatic

Returns a uniformly distributed random orientation.

Returns
Random orientation represented as a Rotation3D

◆ ranTransform3D()

static rw::math::Transform3D<T> ranTransform3D ( const double  translationLength = 1)
inlinestatic

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

Parameters
translationLength[in]
Returns
Random Transform3D

◆ ranWeightedDir()

static rw::math::Q ranWeightedDir ( size_t  dim,
const rw::math::Q weights,
double  length = 1 
)
static

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

◆ round()

static double round ( double  d)
inlinestatic

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.

◆ seed() [1/2]

static void seed ( unsigned  seed)
static

Seeds the random number generator.

Note
Uses boost::random

◆ seed() [2/2]

static void seed ( )
static

Seeds the random number generator with current time of day.

Note
Uses boost::random

◆ sign() [1/2]

static double sign ( double  s)
inlinestatic

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() [2/2]

static Q sign ( const Q q)
inlinestatic

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

◆ skew() [1/2]

static boost::numeric::ublas::bounded_matrix<R, 3, 3> skew ( const boost::numeric::ublas::bounded_vector< R, 3 > &  s)
inlinestatic

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() [2/2]

static Eigen::Matrix<R, 3, 3> skew ( const Vector3D< R > &  s)
inlinestatic

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] $

◆ sqr()

static T sqr ( const T &  d)
inlinestatic

The square of d.

Parameters
d[in] Number to square
Returns
d * d

◆ toStdVector() [1/2]

static std::vector<double> toStdVector ( const ARR &  tmp,
int  size 
)
inlinestatic

convert a math vector type to an vector of doubles. The input should have the index operator () in order to use this conversion

Parameters
tmp[in] input
size[in] length of tmp
Returns
vector of doubles

◆ toStdVector() [2/2]

static std::vector<double> toStdVector ( const MAT &  tmp,
int  size1,
int  size2 
)
inlinestatic

convert a math matrix type to an vector of doubles. The input should have the index operator (x,y) in order to use this conversion

Parameters
tmp[in] input matrix type
size1[in] width of tmp
size2[in] height of tmp
Returns
vector of doubles

◆ zyxToRotation3D()

static Rotation3D<A> zyxToRotation3D ( roll,
pitch,
yaw 
)
inlinestatic

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

The documentation for this class was generated from the following file: