int rotCode(const Mat3 &R) { #define ALMOST_ONE 0.9 int i, j; Vect3 axis, ref; Vect3 dirs[6] = {Vect3::I, Vect3::I_, Vect3::J, Vect3::J_, Vect3::K , Vect3::K_}; axis = R.zcol(); ref = R.xcol(); for (i = 0; axis.dot(dirs[i]) < ALMOST_ONE; i++); for (j = 0; ref.dot(dirs[((i & ~1) + 2 + j) % 6]) < ALMOST_ONE; j++); return i * 4 + j; #undef ALMOST_ONE }