13 using namespace tvmet;
17 static const double PI = 3.14159265358979323846;
37 const double sth = sin(q);
38 const double vth = 1.0 - cos(q);
44 const double axx = ax*ax*vth;
45 const double ayy = ay*ay*vth;
46 const double azz = az*az*vth;
47 const double axy = ax*ay*vth;
48 const double ayz = ay*az*vth;
49 const double azx = az*ax*vth;
55 out_R = 1.0 - azz - ayy, -az + axy, ay + azx,
56 az + axy, 1.0 - azz - axx, -ax + ayz,
57 -ay + azx, ax + ayz, 1.0 - ayy - axx;
63 using ::std::numeric_limits;
65 double alpha = (r(0,0) + r(1,1) + r(2,2) - 1.0) / 2.0;
67 if(fabs(alpha - 1.0) < 1.0e-6) {
71 double th = acos(alpha);
74 if (s < numeric_limits<double>::epsilon()) {
75 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 );
78 double k = -0.5 * th / s;
80 return Vector3( (r(1,2) - r(2,1)) * k,
81 (r(2,0) - r(0,2)) * k,
82 (r(0,1) - r(1,0)) * k );
89 double roll, pitch, yaw;
91 if ((fabs(m(0,0))<fabs(m(2,0))) && (fabs(m(1,0))<fabs(m(2,0)))) {
96 }
else if (sp > 1.0) {
101 roll = atan2(sp*m(0,1)+m(1,2),
105 (roll < 0.0) ? (roll +=
PI) : (roll -=
PI);
107 double sr=sin(roll), cr=cos(roll);
109 yaw = atan2(sr*m(1,1)+cr*m(1,2),
110 sr*m(0,1)+cr*m(0,2));
112 yaw = atan2(-sr*m(1,1)-cr*m(1,2),
113 -sr*m(0,1)-cr*m(0,2));
116 yaw = atan2(m(1,0), m(0,0));
117 const double sa = sin(yaw);
118 const double ca = cos(yaw);
119 pitch = atan2(-m(2,0), ca*m(0,0)+sa*m(1,0));
120 roll = atan2(sa*m(0,2)-ca*m(1,2), -sa*m(0,1)+ca*m(1,1));
122 return Vector3(roll, pitch, yaw);
128 const double cr = cos(r), sr = sin(r), cp = cos(p), sp = sin(p), cy = cos(y), sy = sin(y);
130 out_R(0,1)= sr*sp*cy - cr*sy;
131 out_R(0,2)= cr*sp*cy + sr*sy;
133 out_R(1,1)= sr*sp*sy + cr*cy;
134 out_R(1,2)= cr*sp*sy - sr*cy;
143 double det = m(0,0)*(m(1,1)*m(2,2)-m(1,2)*m(2,1)) - m(0,1)*(m(1,0)*m(2,2)-m(1,2)*m(2,0)) + m(0,2)*(m(1,0)*m(2,1)-m(1,1)*m(2,0));
145 if(fabs(det) < std::numeric_limits<double>::epsilon()){
146 throw std::string(
"Invrse matrix cannot be calculated.");
150 (m(1,1)*m(2,2)-m(1,2)*m(2,1)) / det, (m(0,2)*m(2,1)-m(0,1)*m(2,2)) / det, (m(0,1)*m(1,2)-m(0,2)*m(1,1)) / det,
151 (m(1,2)*m(2,0)-m(1,0)*m(2,2)) / det, (m(0,0)*m(2,2)-m(0,2)*m(2,0)) / det, (m(0,2)*m(1,0)-m(0,0)*m(1,2)) / det,
152 (m(1,0)*m(2,1)-m(1,1)*m(2,0)) / det, (m(0,1)*m(2,0)-m(0,0)*m(2,1)) / det, (m(0,0)*m(1,1)-m(0,1)*m(1,0)) / det;
157 return all_elements( m *
trans(m) == tvmet::identity<Matrix33>() );
HRP_UTIL_EXPORT bool isOrthogonalMatrix(Matrix33 &m)
HRP_UTIL_EXPORT void calcRotFromRpy(Matrix33 &out_R, double r, double p, double y)
void calcInverse(Matrix33 &inv, const Matrix33 &m)
png_infop png_bytep * trans
double det(const dmatrix &_a)
HRP_UTIL_EXPORT Vector3 rpyFromRot(const Matrix33 &m)
fMat inv(const fMat &mat)
HRP_UTIL_EXPORT void calcRodrigues(Matrix33 &out_R, const Vector3 &axis, double q)
HRP_UTIL_EXPORT Vector3 omegaFromRot(const Matrix33 &r)