Package org.robwork.sdurw_math
Class Math
- java.lang.Object
-
- org.robwork.sdurw_math.Math
-
public class Math extends java.lang.ObjectUtility 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 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 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 Vector3Dclamp(Vector3D q, Vector3D min, Vector3D max)Clamps values of q with min and max
static QclampQ(Q q, PairQ 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 QuaternioneaaToQuaternion(EAA eaa)Equivalent angle axis to quaternion conversion.
static Quaternion_feaaToQuaternion(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 Rotation3DffromStdVectorToMat(vector_d data, Rotation3Df tmp, int size1, int size2)convert a vector of doubles to a matrix math type.static Rotation3DfromStdVectorToMat(vector_d data, Rotation3D tmp, int size1, int size2)convert a vector of doubles to a matrix math type.static Transform3DffromStdVectorToMat(vector_d data, Transform3Df tmp, int size1, int size2)convert a vector of doubles to a matrix math type.static Transform3DfromStdVectorToMat(vector_d data, Transform3D tmp, int size1, int size2)convert a vector of doubles to a matrix math type.static Rotation3DffromStdVectorToMat_f(vector_f data, Rotation3Df tmp, int size1, int size2)convert a vector of doubles to a matrix math type.static Rotation3DfromStdVectorToMat_f(vector_f data, Rotation3D tmp, int size1, int size2)convert a vector of doubles to a matrix math type.static Transform3DffromStdVectorToMat_f(vector_f data, Transform3Df tmp, int size1, int size2)convert a vector of doubles to a matrix math type.static Transform3DfromStdVectorToMat_f(vector_f data, Transform3D tmp, int size1, int size2)convert a vector of doubles to a matrix math type.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 EAAquaternionToEAA(Quaternion quat)Quaternion to equivalent angle axis conversion.
static EAAfquaternionToEAA(Quaternion_f 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(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 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 QuaternionranQuaternion()Returns a uniformly distributed random orientation.
static Quaternion_franQuaternion_f()Returns a uniformly distributed random orientation.
static Rotation3DranRotation3D()Returns a uniformly distributed random orientation.
static Rotation3DfranRotation3D_f()Returns a uniformly distributed random orientation.
static Transform3DranTransform3D()Returns random Transform3D based on ranDir (using the standard normal
distribution) and ranRotation3D (using a uniform distribution).
static Transform3DranTransform3D(double translationLength)Returns random Transform3D based on ranDir (using the standard normal
distribution) and ranRotation3D (using a uniform distribution).
static Transform3DfranTransform3D_f()Returns random Transform3D based on ranDir (using the standard normal
distribution) and ranRotation3D (using a uniform distribution).
static Transform3DfranTransform3D_f(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(Vector3D s)static EigenMatrix3fskew(Vector3Df s)static Qsqr(Q q)The squares of the elements of q.static Qsqrt(Q q)The square roots of the elements of q.static vector_dtoStdVector(Rotation3Df tmp, int size1, int size2)static vector_dtoStdVector(Rotation3D tmp, int size1, int size2)static vector_dtoStdVector(Transform3Df tmp, int size1, int size2)static vector_dtoStdVector(Transform3D tmp, int size1, int size2)static vector_dtoStdVector(Vector3Df tmp, int size)static vector_dtoStdVector(Vector3D tmp, int size)static Rotation3DzyxToRotation3D(double roll, double pitch, double yaw)this function converts a EAA object to a Quaternion
static Rotation3DfzyxToRotation3D(float roll, float pitch, float 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, PairQ 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 Vector3D clamp(Vector3D q, Vector3D min, Vector3D 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(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 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 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 zpitch- [in] rotation around yyaw- [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 zpitch- [in] rotation around yyaw- [in] rotation around x
- Returns:
- a Quaternion object that represents the converted EAA
-
skew
public static EigenMatrix3d skew(Vector3D s)
-
skew
public static EigenMatrix3f skew(Vector3Df s)
-
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 inputtmp- [out] the outputsize1- [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 inputtmp- [out] the outputsize1- [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 inputtmp- [out] the outputsize1- [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 inputtmp- [out] the outputsize1- [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 inputtmp- [out] the outputsize1- [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 inputtmp- [out] the outputsize1- [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 inputtmp- [out] the outputsize1- [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 inputtmp- [out] the outputsize1- [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(Transform3Df 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)
-
-