1#ifndef ROBOTOC_ROTATION_HPP_ 
    2#define ROBOTOC_ROTATION_HPP_ 
    5#include "Eigen/Geometry" 
   15template <
typename VectorType>
 
   17    const Eigen::MatrixBase<VectorType>& quat_xyzw) {
 
   18  assert(quat_xyzw.size() == 4);
 
   19  return Eigen::Quaterniond(quat_xyzw).toRotationMatrix();
 
   28template <
typename VectorType>
 
   30    const Eigen::MatrixBase<VectorType>& normal_vector) {
 
   31  assert(normal_vector.size() == 3);
 
   33  const double nx = normal_vector.coeff(0);
 
   34  const double ny = normal_vector.coeff(1);
 
   35  const double nz = normal_vector.coeff(2);
 
   36  const double nxny_norm = std::sqrt(nx*nx + ny*ny);
 
   37  constexpr double eps = std::numeric_limits<double>::epsilon();
 
   38  if (nxny_norm < eps) 
return Eigen::Matrix3d::Identity();
 
   40  R <<    ny/nxny_norm,   -nx/nxny_norm,         0.,
 
   41       nx*nz/nxny_norm, ny*nz/nxny_norm, -nxny_norm,
 
   51template <
typename MatrixType>
 
   53    const Eigen::MatrixBase<MatrixType>& R) {
 
   54  assert(R.rows() == 3);
 
   55  assert(R.cols() == 3);
 
   56  return Eigen::Quaterniond(R).coeffs();
 
   64template <
typename VectorType>
 
   66    const Eigen::MatrixBase<VectorType>& normal_vector) {
 
   86    const double norm = R.coeff(1, 1) * R.coeff(1, 1) + R.coeff(1, 2) + R.coeff(1, 2);
 
   88    R.coeffRef(0, 0) = 1.0;
 
   89    R.coeffRef(0, 1) = 0.0;
 
   90    R.coeffRef(0, 2) = 0.0;
 
   91    R.coeffRef(1, 0) = 0.0;
 
   92    R.coeffRef(2, 0) = 0.0;
 
   95    const double norm = R.coeff(0, 0) * R.coeff(0, 0) + R.coeff(0, 2) + R.coeff(0, 2);
 
   97    R.coeffRef(0, 1) = 0.0;
 
   98    R.coeffRef(1, 0) = 0.0;
 
   99    R.coeffRef(1, 1) = 1.0;
 
  100    R.coeffRef(1, 2) = 0.0;
 
  101    R.coeffRef(2, 1) = 0.0;
 
  104    const double norm = R.coeff(0, 0) * R.coeff(0, 0) + R.coeff(0, 1) + R.coeff(0, 1);
 
  106    R.coeffRef(0, 2) = 0.0;
 
  107    R.coeffRef(1, 2) = 0.0;
 
  108    R.coeffRef(2, 0) = 0.0;
 
  109    R.coeffRef(2, 1) = 0.0;
 
  110    R.coeffRef(2, 2) = 1.0;
 
void ProjectRotationMatrix(Eigen::Matrix3d &R, const ProjectionAxis axis)
Projects a rotation matrix onto a specified axis.
Definition: rotation.hpp:84
 
Eigen::Vector4d QuaternionFromRotationMatrix(const Eigen::MatrixBase< MatrixType > &R)
Convert a rotation matrix to a quaternion vector (x, y, z, w).
Definition: rotation.hpp:52
 
ProjectionAxis
Projection axis of the rotation.
Definition: rotation.hpp:74
 
Eigen::Matrix3d RotationMatrixFromNormalVector(const Eigen::MatrixBase< VectorType > &normal_vector)
Convert a normal vector to its surface Rotation matrix.
Definition: rotation.hpp:29
 
Eigen::Vector4d QuaternionFromNormalVector(const Eigen::MatrixBase< VectorType > &normal_vector)
Convert a normal vector to its surface quaternion (x, y, z, w).
Definition: rotation.hpp:65
 
Eigen::Matrix3d RotationMatrixFromQuaternion(const Eigen::MatrixBase< VectorType > &quat_xyzw)
Convert quaternion vector (x, y, z, w) to a Rotation matrix.
Definition: rotation.hpp:16
 
Definition: constraint_component_base.hpp:17