From 2dc46b783aa80812dc44957886a06f61c50660e7 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Sat, 16 May 2020 00:58:40 +0200 Subject: [PATCH] simplified and tested --- python/damask/_rotation.py | 7 ++----- python/tests/test_Rotation.py | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/python/damask/_rotation.py b/python/damask/_rotation.py index 059f148a4..38294f75e 100644 --- a/python/damask/_rotation.py +++ b/python/damask/_rotation.py @@ -112,11 +112,8 @@ class Rotation: B = 2.0 * np.dot(self.quaternion[1:],other) C = 2.0 * _P*self.quaternion[0] - return np.array([ - A*other[0] + B*self.quaternion[1] + C*(self.quaternion[2]*other[2] - self.quaternion[3]*other[1]), - A*other[1] + B*self.quaternion[2] + C*(self.quaternion[3]*other[0] - self.quaternion[1]*other[2]), - A*other[2] + B*self.quaternion[3] + C*(self.quaternion[1]*other[1] - self.quaternion[2]*other[0]), - ]) + return A*other + B*self.quaternion[1:] + C * np.cross(self.quaternion[1:],other) + elif other.shape == (3,3,): # rotate a single (3x3)-matrix return np.dot(self.asMatrix(),np.dot(other,self.asMatrix().T)) elif other.shape == (3,3,3,3,): diff --git a/python/tests/test_Rotation.py b/python/tests/test_Rotation.py index b7442035f..ffa1548d7 100644 --- a/python/tests/test_Rotation.py +++ b/python/tests/test_Rotation.py @@ -300,3 +300,10 @@ class TestRotation: f = Rotation._get_pyramid_order(a,'forward') b = Rotation._get_pyramid_order(a,'backward') assert np.all(np.take_along_axis(np.take_along_axis(a,f,-1),b,-1) == a) + + + @pytest.mark.parametrize('x',[np.random.rand(3), + np.random.rand(3,3)]) + def test_rotation_identity(self,x): + R = Rotation() + assert np.allclose(x,R*x)