RatsMatrix.cpp
Go to the documentation of this file.
00001 #include "RatsMatrix.h"
00002 
00003 namespace rats
00004 {
00005   hrp::Vector3 matrix_log(const hrp::Matrix33& m) {
00006     hrp::Vector3 mlog;
00007     double q0, th;
00008     hrp::Vector3 q;
00009     double norm;
00010   
00011     Eigen::Quaternion<double> eiq(m);
00012     q0 = eiq.w();
00013     q = eiq.vec();
00014     norm = q.norm();
00015     if (norm > 0) {
00016       if ((q0 > 1.0e-10) || (q0 < -1.0e-10)) {
00017         th = 2 * std::atan(norm / q0);
00018       } else if (q0 > 0) {
00019         th = M_PI / 2;
00020       } else {
00021         th = -M_PI / 2;
00022       }
00023       mlog = (th / norm) * q ;
00024     } else {
00025       mlog = hrp::Vector3::Zero();
00026     }
00027     return mlog;
00028   }
00029 
00030   // matrix product using quaternion normalization
00031   void rotm3times (hrp::Matrix33& m12, const hrp::Matrix33& m1, const hrp::Matrix33& m2) {
00032     Eigen::Quaternion<double> eiq1(m1);
00033     Eigen::Quaternion<double> eiq2(m2);
00034     Eigen::Quaternion<double> eiq3;
00035     eiq3 = eiq1 * eiq2;
00036     eiq3.normalize();
00037     m12 = eiq3.toRotationMatrix();
00038   }
00039 
00040   void difference_rotation(hrp::Vector3& ret_dif_rot, const hrp::Matrix33& self_rot, const hrp::Matrix33& target_rot)
00041   {
00042     //ret_dif_rot = self_rot * hrp::omegaFromRot(self_rot.transpose() * target_rot);
00043     ret_dif_rot = self_rot * hrp::Vector3(rats::matrix_log(hrp::Matrix33(self_rot.transpose() * target_rot)));
00044   }
00045 
00046   void mid_rot(hrp::Matrix33& mid_rot, const double p, const hrp::Matrix33& rot1, const hrp::Matrix33& rot2, const double eps) {
00047     hrp::Matrix33 r(rot1.transpose() * rot2);
00048     hrp::Vector3 omega(matrix_log(r));
00049     if (eps_eq(omega.norm(),0.0, eps)) { // c1.rot and c2.rot are same
00050       mid_rot = rot1;
00051     } else {
00052       hrp::calcRodrigues(r, omega.normalized(), omega.norm()*p);
00053       //mid_rot = c1.rot * r;
00054       rotm3times(mid_rot, rot1, r);
00055     }
00056   };
00057 
00058   void mid_coords(coordinates& mid_coords, const double p, const coordinates& c1, const coordinates& c2, const double eps) {
00059     mid_coords.pos = (1 - p) * c1.pos + p * c2.pos;
00060     mid_rot(mid_coords.rot, p, c1.rot, c2.rot, eps);
00061   };
00062 
00063 }


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Wed May 15 2019 05:02:18