2
0

IDMath.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /// @file Math utility functions used in inverse dynamics library.
  2. /// Defined here as they may not be provided by the math library.
  3. #ifndef IDMATH_HPP_
  4. #define IDMATH_HPP_
  5. #include "IDConfig.hpp"
  6. namespace btInverseDynamics
  7. {
  8. /// set all elements to zero
  9. void setZero(vec3& v);
  10. /// set all elements to zero
  11. void setZero(vecx& v);
  12. /// set all elements to zero
  13. void setZero(mat33& m);
  14. /// create a skew symmetric matrix from a vector (useful for cross product abstraction, e.g. v x a = V * a)
  15. void skew(vec3& v, mat33* result);
  16. /// return maximum absolute value
  17. idScalar maxAbs(const vecx& v);
  18. #ifndef ID_LINEAR_MATH_USE_EIGEN
  19. /// return maximum absolute value
  20. idScalar maxAbs(const vec3& v);
  21. #endif //ID_LINEAR_MATH_USE_EIGEN
  22. #if (defined BT_ID_HAVE_MAT3X)
  23. idScalar maxAbsMat3x(const mat3x& m);
  24. void setZero(mat3x& m);
  25. // define math functions on mat3x here to avoid allocations in operators.
  26. void mul(const mat33& a, const mat3x& b, mat3x* result);
  27. void add(const mat3x& a, const mat3x& b, mat3x* result);
  28. void sub(const mat3x& a, const mat3x& b, mat3x* result);
  29. #endif
  30. /// get offset vector & transform matrix from DH parameters
  31. /// TODO: add documentation
  32. void getVecMatFromDH(idScalar theta, idScalar d, idScalar a, idScalar alpha, vec3* r, mat33* T);
  33. /// Check if a 3x3 matrix is positive definite
  34. /// @param m a 3x3 matrix
  35. /// @return true if m>0, false otherwise
  36. bool isPositiveDefinite(const mat33& m);
  37. /// Check if a 3x3 matrix is positive semi definite
  38. /// @param m a 3x3 matrix
  39. /// @return true if m>=0, false otherwise
  40. bool isPositiveSemiDefinite(const mat33& m);
  41. /// Check if a 3x3 matrix is positive semi definite within numeric limits
  42. /// @param m a 3x3 matrix
  43. /// @return true if m>=-eps, false otherwise
  44. bool isPositiveSemiDefiniteFuzzy(const mat33& m);
  45. /// Determinant of 3x3 matrix
  46. /// NOTE: implemented here for portability, as determinant operation
  47. /// will be implemented differently for various matrix/vector libraries
  48. /// @param m a 3x3 matrix
  49. /// @return det(m)
  50. idScalar determinant(const mat33& m);
  51. /// Test if a 3x3 matrix satisfies some properties of inertia matrices
  52. /// @param I a 3x3 matrix
  53. /// @param index body index (for error messages)
  54. /// @param has_fixed_joint: if true, positive semi-definite matrices are accepted
  55. /// @return true if I satisfies inertia matrix properties, false otherwise.
  56. bool isValidInertiaMatrix(const mat33& I, int index, bool has_fixed_joint);
  57. /// Check if a 3x3 matrix is a valid transform (rotation) matrix
  58. /// @param m a 3x3 matrix
  59. /// @return true if m is a rotation matrix, false otherwise
  60. bool isValidTransformMatrix(const mat33& m);
  61. /// Transform matrix from parent to child frame,
  62. /// when the child frame is rotated about @param axis by @angle
  63. /// (mathematically positive)
  64. /// @param axis the axis of rotation
  65. /// @param angle rotation angle
  66. /// @param T pointer to transform matrix
  67. void bodyTParentFromAxisAngle(const vec3& axis, const idScalar& angle, mat33* T);
  68. /// Check if this is a unit vector
  69. /// @param vector
  70. /// @return true if |vector|=1 within numeric limits
  71. bool isUnitVector(const vec3& vector);
  72. /// @input a vector in R^3
  73. /// @returns corresponding spin tensor
  74. mat33 tildeOperator(const vec3& v);
  75. /// @param alpha angle in radians
  76. /// @returns transform matrix for ratation with @param alpha about x-axis
  77. mat33 transformX(const idScalar& alpha);
  78. /// @param beta angle in radians
  79. /// @returns transform matrix for ratation with @param beta about y-axis
  80. mat33 transformY(const idScalar& beta);
  81. /// @param gamma angle in radians
  82. /// @returns transform matrix for ratation with @param gamma about z-axis
  83. mat33 transformZ(const idScalar& gamma);
  84. ///calculate rpy angles (x-y-z Euler angles) from a given rotation matrix
  85. /// @param rot rotation matrix
  86. /// @returns x-y-z Euler angles
  87. vec3 rpyFromMatrix(const mat33& rot);
  88. } // namespace btInverseDynamics
  89. #endif // IDMATH_HPP_