Package org.robwork.sdurw
Class Math
- java.lang.Object
-
- org.robwork.sdurw.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 Qabs(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 Vector3Ddabs(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 Vector3Dfabs(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 intceilLog2(int n)Exact implementation of ceil(log_2(n)) for n > 0.static doubleclamp(double val, double min, double max)clamp val to either min or max
static Vector3Ddclamp(Vector3Dd q, Vector3Dd min, Vector3Dd max)Clamps values of q with min and max
static QclampQ(Q q, QPair bounds)Clamps values of q with bounds.first and bounds.second
static QclampQ(Q q, Q min, Q max)Clamps values of q with min and max
voiddelete()static QuaterniondeaaToQuaternion(EAAd eaa)Equivalent angle axis to quaternion conversion.
static QuaternionfeaaToQuaternion(EAAf eaa)Equivalent angle axis to quaternion conversion.
static longfactorial(long n)Factorial
The method does not implement any safe guards for negative numbers of overflow of
numbers.static longgetCPtr(Math obj)static booleanisNaN(double d)Implements an isNaN function
Use to make sure code is independent of specific compile specific implementationsstatic doublemax(Q v)Returns the largest element of v
If the vector has zero length, the method returns 0
static doublemin(Q v)Returns the smallest element of v
If the vector has zero length, the method returns 0
static doubleNaN()Get a value for NaN.
Use to make sure code is independent of specific compile specific implementations
static EAAdquaternionToEAA(Quaterniond quat)Quaternion to equivalent angle axis conversion.
static EAAfquaternionToEAA(Quaternionf quat)Quaternion to equivalent angle axis conversion.
static doubleran()A random double in the range [0, 1[ using a uniform distribution.
Note: Uses boost::randomstatic doubleran(double from, double to)A random double in the range [from, to[ using a uniform distribution.
Note: Uses boost::randomstatic QranDir(long dim)Returns a random direction in dim dimensions using the standard normal
distribution.
The length of the vector is given by length;
static QranDir(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 intranI(int from, int to)A random integer in the range [from, to[ using a uniform distribution.
Note: Uses boost::randomstatic doubleranNormalDist(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 QranQ(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 QranQ(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 QuaterniondranQuaterniond()Returns a uniformly distributed random orientation.
static QuaternionfranQuaternionf()Returns a uniformly distributed random orientation.
static Rotation3DdranRotation3Dd()Returns a uniformly distributed random orientation.
static Rotation3DfranRotation3Df()Returns a uniformly distributed random orientation.
static Transform3DdranTransform3Dd()Returns random Transform3D based on ranDir (using the standard normal
distribution) and ranRotation3D (using a uniform distribution).
static Transform3DdranTransform3Dd(double translationLength)Returns random Transform3D based on ranDir (using the standard normal
distribution) and ranRotation3D (using a uniform distribution).
static Transform3DfranTransform3Df()Returns random Transform3D based on ranDir (using the standard normal
distribution) and ranRotation3D (using a uniform distribution).
static Transform3DfranTransform3Df(double translationLength)Returns random Transform3D based on ranDir (using the standard normal
distribution) and ranRotation3D (using a uniform distribution).
static QranWeightedDir(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 QranWeightedDir(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 doubleround(double d)Rounds off to nearest integer
With some compilers round can be found in math.h.static voidseed()Seeds the random number generator with current time of day
Note: Uses boost::randomstatic voidseed(long seed)Seeds the random number generator.
Note: Uses boost::randomstatic doublesign(double s)Returns the sign of s
If s < 0 it return 0.static Qsign(Q q)Returns the sign of each element
For each element either -1 or 1 is returned depending on the sign.static EigenMatrix3dskew(Vector3Dd s)Constructs a 3x3 skew-symmetric matrix S\in so(3)static EigenMatrix3fskew(Vector3Df s)Constructs a 3x3 skew-symmetric matrix S\in so(3)static Qsqr(Q q)The squares of the elements of q.static Qsqrt(Q q)The square roots of the elements of q.static Rotation3DdzyxToRotation3D(double roll, double pitch, double yaw)this function converts a EAA object to a Quaternion
-
-
-
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 clampedmin- [in] the minimum allowed valuemax- [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 clampmin- [min] The minimum valuemax- [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 clampbounds- [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 clampmin- [min] The minimum valuemax- [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 valuesigma- [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 boundto- [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 dimensionslength- [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 dimensionsweights- [in] Weights to uselength- [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 dimensionsweights- [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.
-
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 zpitch- [in] rotation around yyaw- [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)
-
-