1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| Mat3x3f CIMUSensorView::computeRotationMatrix(float roll, float pitch) { Mat3x3f rot1, rot2; computeRotationMatrix(Vec3f(1, 0, 0), roll, rot1); computeRotationMatrix(Vec3f(0, 1, 0), pitch, rot2); return rot2 * rot1; }
void CIMUSensorView::computeRotationMatrix(Vec3f axis, float angle, Mat3x3f& rot) { float x, y, z; x = axis[0]; y = axis[1]; z = axis[2];
rot(0, 0) = x * x + (y * y + z * z) * cos(angle); rot(1, 1) = y * y + (x * x + z * z) * cos(angle); rot(2, 2) = z * z + (x * x + y * y) * cos(angle); rot(0, 1) = (1 - cos(angle)) * x * y + z * sin(angle); rot(1, 0) = (1 - cos(angle)) * x * y - z * sin(angle); rot(0, 2) = (1 - cos(angle)) * x * z - y * sin(angle); rot(2, 0) = (1 - cos(angle)) * z * x + y * sin(angle); rot(1, 2) = (1 - cos(angle)) * y * z + x * sin(angle); rot(2, 1) = (1 - cos(angle)) * z * y - x * sin(angle);
rot.transpose(); };
|