8 #ifndef LIBBIOMIMETICS_SPATIAL_H     9 #define LIBBIOMIMETICS_SPATIAL_H    13 #include <eigen3/Eigen/Dense>    17 #include <type_traits>    29   static_assert(std::is_floating_point<T>::value,
    30                 "must use floating point value");
    33   X.template topLeftCorner<3, 3>() = R;
    34   X.template bottomRightCorner<3, 3>() = R;
    44   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
    45                 "Must have 6x1 vector");
    47   m << 0, -v(2), v(1), 0, 0, 0, v(2), 0, -v(0), 0, 0, 0, -v(1), v(0), 0, 0, 0,
    50       0, -v(5), v(4), 0, -v(2), v(1), v(5), 0, -v(3), v(2), 0, -v(0), -v(4),
    51       v(3), 0, -v(1), v(0), 0;
    62   f << 0, -v(2), v(1), 0, -v(5), v(4), v(2), 0, -v(0), v(5), 0, -v(3), -v(1),
    63       v(0), 0, -v(4), v(3), 0, 0, 0, 0, 0, -v(2), v(1), 0, 0, 0, v(2), 0, -v(0),
    64       0, 0, 0, -v(1), v(0), 0;
    74                         const Eigen::MatrixBase<T>& b) {
    75   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
    76                 "Must have 6x1 vector");
    78   mv << a(1) * b(2) - a(2) * b(1), a(2) * b(0) - a(0) * b(2),
    79       a(0) * b(1) - a(1) * b(0),
    80       a(1) * b(5) - a(2) * b(4) + a(4) * b(2) - a(5) * b(1),
    81       a(2) * b(3) - a(0) * b(5) - a(3) * b(2) + a(5) * b(0),
    82       a(0) * b(4) - a(1) * b(3) + a(3) * b(1) - a(4) * b(0);
    92                        const Eigen::MatrixBase<T>& b) {
    93   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
    94                 "Must have 6x1 vector");
    96   mv << b(2) * a(1) - b(1) * a(2) - b(4) * a(5) + b(5) * a(4),
    97       b(0) * a(2) - b(2) * a(0) + b(3) * a(5) - b(5) * a(3),
    98       b(1) * a(0) - b(0) * a(1) - b(3) * a(4) + b(4) * a(3),
    99       b(5) * a(1) - b(4) * a(2), b(3) * a(2) - b(5) * a(0),
   100       b(4) * a(0) - b(3) * a(1);
   107 template <
typename T>
   109   static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
   110                 "Must have 6x6 matrix");
   114   H.template topLeftCorner<3, 3>() = R;
   115   H.template topRightCorner<3, 1>() = 
matToSkewVec(skewR * R.transpose());
   123 template <
typename T>
   125   static_assert(T::ColsAtCompileTime == 4 && T::RowsAtCompileTime == 4,
   126                 "Must have 4x4 matrix");
   130   X.template topLeftCorner<3, 3>() = R;
   132   X.template bottomRightCorner<3, 3>() = R;
   139 template <
typename T, 
typename T2>
   141                   const Eigen::MatrixBase<T2>& r) {
   142   static_assert(T::ColsAtCompileTime == 3 && T::RowsAtCompileTime == 3,
   143                 "Must have 3x3 matrix");
   144   static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
   145                 "Must have 3x1 matrix");
   147   X.template topLeftCorner<3, 3>() = R;
   148   X.template bottomRightCorner<3, 3>() = R;
   156 template <
typename T>
   158   static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
   159                 "Must have 6x6 matrix");
   167 template <
typename T>
   169   static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
   170                 "Must have 6x6 matrix");
   173       -
matToSkewVec(R.transpose() * X.template bottomLeftCorner<3, 3>());
   180 template <
typename T>
   182   static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
   183                 "Must have 6x6 matrix");
   186       -
matToSkewVec(R.transpose() * X.template bottomLeftCorner<3, 3>());
   194 template <
typename T>
   198   if (axis == CoordinateAxis::X)
   200   else if (axis == CoordinateAxis::Y)
   206     phi.template bottomLeftCorner<3, 1>() = v;
   208     phi.template topLeftCorner<3, 1>() = v;
   210     throw std::runtime_error(
"Unknown motion subspace");
   218 template <
typename T>
   225     if (axis == CoordinateAxis::X)
   227     else if (axis == CoordinateAxis::Y)
   229     else if (axis == CoordinateAxis::Z)
   234     throw std::runtime_error(
"Unknown joint xform\n");
   244 template <
typename T>
   246                                          const Eigen::MatrixBase<T>& dims) {
   247   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 3,
   248                 "Must have 3x1 vector");
   251   for (
int i = 0; i < 3; i++) I(i, i) -= dims(i) * dims(i);
   260 template <
typename T, 
typename T2>
   262                              const Eigen::MatrixBase<T2>& x) {
   263   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
   264                 "Must have 6x1 vector");
   265   static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
   266                 "Must have 3x1 vector");
   276 template <
typename T>
   278   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
   279                 "Must have 6x1 vector");
   288 template <
typename T, 
typename T2>
   290                                  const Eigen::MatrixBase<T2>& v) {
   291   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
   292                 "Must have 6x1 vector");
   293   static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 6,
   294                 "Must have 6x1 vector");
   298   acc = a.template tail<3>() + v.template head<3>().cross(v.template tail<3>());
   306 template <
typename T, 
typename T2, 
typename T3>
   308                                  const Eigen::MatrixBase<T2>& v,
   309                                  const Eigen::MatrixBase<T3>& x) {
   310   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 6,
   311                 "Must have 6x1 vector");
   312   static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 6,
   313                 "Must have 6x1 vector");
   314   static_assert(T3::ColsAtCompileTime == 1 && T3::RowsAtCompileTime == 3,
   315                 "Must have 3x1 vector");
   328 template <
typename T, 
typename T2>
   330                  const Eigen::MatrixBase<T2>& p) {
   331   static_assert(T::ColsAtCompileTime == 6 && T::RowsAtCompileTime == 6,
   332                 "Must have 6x6 vector");
   333   static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
   334                 "Must have 3x1 vector");
   347 template <
typename T, 
typename T2>
   349                          const Eigen::MatrixBase<T2>& p) {
   350   static_assert(T::ColsAtCompileTime == 1 && T::RowsAtCompileTime == 3,
   351                 "Must have 3x1 vector");
   352   static_assert(T2::ColsAtCompileTime == 1 && T2::RowsAtCompileTime == 3,
   353                 "Must have 3x1 vector");
   355   fs.template topLeftCorner<3, 1>() = p.cross(f);
   356   fs.template bottomLeftCorner<3, 1>() = f;
   362 #endif  // LIBBIOMIMETICS_SPATIAL_H auto forceToSpatialForce(const Eigen::MatrixBase< T > &f, const Eigen::MatrixBase< T2 > &p)
 
auto spatialToLinearVelocity(const Eigen::MatrixBase< T > &v, const Eigen::MatrixBase< T2 > &x)
 
auto forceCrossProduct(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b)
 
Mat3< T > coordinateRotation(CoordinateAxis axis, T theta)
 
typename Eigen::Matrix< T, 6, 6 > Mat6
 
Mat6< T > jointXform(JointType joint, CoordinateAxis axis, T q)
 
typename Eigen::Matrix< T, 3, 3 > Mat3
 
typename Eigen::Matrix< T, 4, 4 > Mat4
 
typename Eigen::Matrix< T, 3, 1 > Vec3
 
auto translationFromSXform(const Eigen::MatrixBase< T > &X)
 
auto spatialToLinearAcceleration(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T2 > &v)
 
typename Eigen::Matrix< T, 6, 6 > SXform
 
auto sXFormPoint(const Eigen::MatrixBase< T > &X, const Eigen::MatrixBase< T2 > &p)
 
typename Eigen::Matrix< T, 6, 1 > SVec
 
SXform< T > spatialRotation(CoordinateAxis axis, T theta)
 
auto motionCrossMatrix(const Eigen::MatrixBase< T > &v)
 
auto createSXform(const Eigen::MatrixBase< T > &R, const Eigen::MatrixBase< T2 > &r)
 
auto sxformToHomogeneous(const Eigen::MatrixBase< T > &X)
 
auto motionCrossProduct(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T > &b)
 
auto homogeneousToSXform(const Eigen::MatrixBase< T > &H)
 
Mat3< typename T::Scalar > vectorToSkewMat(const Eigen::MatrixBase< T > &v)
 
Vec3< typename T::Scalar > matToSkewVec(const Eigen::MatrixBase< T > &m)
 
SVec< T > jointMotionSubspace(JointType joint, CoordinateAxis axis)
 
auto forceCrossMatrix(const Eigen::MatrixBase< T > &v)
 
Mat3< typename T::Scalar > rotInertiaOfBox(typename T::Scalar mass, const Eigen::MatrixBase< T > &dims)
 
typename Eigen::Matrix< T, 3, 3 > RotMat
 
auto rotationFromSXform(const Eigen::MatrixBase< T > &X)
 
auto spatialToAngularVelocity(const Eigen::MatrixBase< T > &v)
 
MX f(const MX &x, const MX &u)
 
auto invertSXform(const Eigen::MatrixBase< T > &X)