19 static const double PI = 3.14159265358979323846;
39 const double sth = sin(q);
40 const double vth = 1.0 - cos(q);
46 const double axx = ax*ax*vth;
47 const double ayy = ay*ay*vth;
48 const double azz = az*az*vth;
49 const double axy = ax*ay*vth;
50 const double ayz = ay*az*vth;
51 const double azx = az*ax*vth;
57 out_R << 1.0 - azz - ayy, -az + axy, ay + azx,
58 az + axy, 1.0 - azz - axx, -ax + ayz,
59 -ay + azx, ax + ayz, 1.0 - ayy - axx;
65 using ::std::numeric_limits;
67 double alpha = (r(0,0) + r(1,1) + r(2,2) - 1.0) / 2.0;
70 if (alpha > 1.0 + 1.0e-6) {
71 cerr << scientific << setprecision(16);
72 cerr <<
"alpha exceeded the upper limit in omegaFromRot" << endl;
73 cerr <<
"alpha=" << alpha << endl;
74 cerr <<
"r=" << r << endl;
79 if(fabs(alpha - 1.0) < 1.0e-12) {
80 return Vector3::Zero();
83 double th = acos(alpha);
86 if (s < numeric_limits<double>::epsilon()) {
87 return Vector3( sqrt((r(0,0)+1)*0.5)*th, sqrt((r(1,1)+1)*0.5)*th, sqrt((r(2,2)+1)*0.5)*th );
90 double k = -0.5 * th / s;
92 return Vector3( (r(1,2) - r(2,1)) * k,
93 (r(2,0) - r(0,2)) * k,
94 (r(0,1) - r(1,0)) * k );
101 double roll, pitch, yaw;
103 if ((fabs(m(0,0))<fabs(m(2,0))) && (fabs(m(1,0))<fabs(m(2,0)))) {
108 }
else if (sp > 1.0) {
113 roll = atan2(sp*m(0,1)+m(1,2),
117 (roll < 0.0) ? (roll +=
PI) : (roll -=
PI);
119 double sr=sin(roll), cr=cos(roll);
121 yaw = atan2(sr*m(1,1)+cr*m(1,2),
122 sr*m(0,1)+cr*m(0,2));
124 yaw = atan2(-sr*m(1,1)-cr*m(1,2),
125 -sr*m(0,1)-cr*m(0,2));
128 yaw = atan2(m(1,0), m(0,0));
129 const double sa = sin(yaw);
130 const double ca = cos(yaw);
131 pitch = atan2(-m(2,0), ca*m(0,0)+sa*m(1,0));
132 roll = atan2(sa*m(0,2)-ca*m(1,2), -sa*m(0,1)+ca*m(1,1));
134 return Vector3(roll, pitch, yaw);
140 const double cr = cos(r), sr = sin(r), cp = cos(p), sp = sin(p), cy = cos(y), sy = sin(y);
142 out_R(0,1)= sr*sp*cy - cr*sy;
143 out_R(0,2)= cr*sp*cy + sr*sy;
145 out_R(1,1)= sr*sp*sy + cr*cy;
146 out_R(1,2)= cr*sp*sy - sr*cy;
153 Matrix33 w(m * m.transpose() - Matrix33::Identity());
154 return (abs(
w.array())<1.0e-12).all();
HRP_UTIL_EXPORT bool isOrthogonalMatrix(Matrix33 &m)
HRP_UTIL_EXPORT void calcRotFromRpy(Matrix33 &out_R, double r, double p, double y)
HRP_UTIL_EXPORT Vector3 rpyFromRot(const Matrix33 &m)
HRP_UTIL_EXPORT void calcRodrigues(Matrix33 &out_R, const Vector3 &axis, double q)
HRP_UTIL_EXPORT Vector3 omegaFromRot(const Matrix33 &r)