def test_euler_instability(): # Test for numerical errors in mat2euler # problems arise for cos(y) near 0 po2 = pi / 2 zyx = po2, po2, po2 M = nea.euler2mat(*zyx) # Round trip M_back = nea.euler2mat(*nea.mat2euler(M)) yield assert_true, np.allclose(M, M_back) # disturb matrix slightly M_e = M - FLOAT_EPS # round trip to test - OK M_e_back = nea.euler2mat(*nea.mat2euler(M_e)) yield assert_true, np.allclose(M_e, M_e_back) # not so with crude routine M_e_back = nea.euler2mat(*crude_mat2euler(M_e)) yield assert_false, np.allclose(M_e, M_e_back)
def test_euler_mat(): M = nea.euler2mat() yield assert_array_equal, M, np.eye(3) for x, y, z in eg_rots: M1 = nea.euler2mat(z, y, x) M2 = sympy_euler(z, y, x) yield assert_array_almost_equal, M1, M2 M3 = np.dot(x_only(x), np.dot(y_only(y), z_only(z))) yield assert_array_almost_equal, M1, M3 zp, yp, xp = nea.mat2euler(M1) # The parameters may not be the same as input, but they give the # same rotation matrix M4 = nea.euler2mat(zp, yp, xp) yield assert_array_almost_equal, M1, M4