def test_rotate(self,default,update,reference_dir,Eulers): modified = copy.deepcopy(default) modified.rotate(Rotation.from_Eulers(Eulers,degrees=True)) tag = 'Eulers={}-{}-{}'.format(*Eulers) reference = os.path.join(reference_dir,'rotate_{}.geom'.format(tag)) if update: modified.to_file(reference) assert geom_equal(modified,Geom.from_file(reference))
def test_Rodrigues(self, default, normalise, P): c = np.array([P * -1, P * -1, P * -1, 1.]) for rot in default: m = rot.as_matrix() o = Rotation.from_Rodrigues(rot.as_Rodrigues() * c, normalise, P).as_matrix() ok = np.allclose(m, o, atol=atol) print(m, o) assert ok and np.isclose(np.linalg.det(o), 1.0)
def test_Eulers(self, default, degrees): for rot in default: m = rot.as_quaternion() o = Rotation.from_Eulers(rot.as_Eulers(degrees), degrees).as_quaternion() ok = np.allclose(m, o, atol=atol) if np.isclose(rot.as_quaternion()[0], 0.0, atol=atol): ok = ok or np.allclose(m * -1., o, atol=atol) print(m, o, rot.as_quaternion()) assert ok and np.isclose(np.linalg.norm(o), 1.0)
def test_matrix(self, default): for rot in default: m = rot.as_axis_angle() o = Rotation.from_axis_angle(rot.as_axis_angle()).as_axis_angle() ok = np.allclose(m, o, atol=atol) if np.isclose(m[3], np.pi, atol=atol): ok = ok or np.allclose( m * np.array([-1., -1., -1., 1.]), o, atol=atol) print(m, o, rot.as_quaternion()) assert ok and np.isclose(np.linalg.norm(o[:3]), 1.0) and o[3] <= np.pi + 1.e-9