again some more tests
This commit is contained in:
parent
1c53a37de4
commit
3e00269179
|
@ -112,10 +112,14 @@ class Rotation:
|
||||||
return A*other + B*self.quaternion[1:] + C * np.cross(self.quaternion[1:],other)
|
return A*other + B*self.quaternion[1:] + C * np.cross(self.quaternion[1:],other)
|
||||||
|
|
||||||
elif other.shape == (3,3,):
|
elif other.shape == (3,3,):
|
||||||
return np.dot(self.as_matrix(),np.dot(other,self.as_matrix().T))
|
R = self.as_matrix()
|
||||||
|
return np.dot(R,np.dot(other,R.T))
|
||||||
elif other.shape == (3,3,3,3,):
|
elif other.shape == (3,3,3,3,):
|
||||||
R = self.as_matrix()
|
R = self.as_matrix()
|
||||||
return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other)
|
RR = np.outer(R, R)
|
||||||
|
RRRR = np.outer(RR, RR).reshape(4 * (3,3))
|
||||||
|
axes = ((0, 2, 4, 6), (0, 1, 2, 3))
|
||||||
|
return np.tensordot(RRRR, other, axes)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Can only rotate vectors, 2nd order ternsors, and 4th order tensors')
|
raise ValueError('Can only rotate vectors, 2nd order ternsors, and 4th order tensors')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -154,8 +154,37 @@ class TestRotation:
|
||||||
if np.isclose(m[3],np.pi,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)
|
ok = ok or np.allclose(m*np.array([-1.,-1.,-1.,1.]),o,atol=atol)
|
||||||
print(m,o,rot.as_quaternion())
|
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-7
|
assert ok and np.isclose(np.linalg.norm(o[:3]),1.0) and o[3]<=np.pi+1.e-9
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('forward,backward',[(Rotation.ro2qu,Rotation.qu2ro),
|
||||||
|
#(Rotation.ro2om,Rotation.om2ro),
|
||||||
|
#(Rotation.ro2eu,Rotation.eu2ro),
|
||||||
|
(Rotation.ro2ax,Rotation.ax2ro),
|
||||||
|
(Rotation.ro2ho,Rotation.ho2ro),
|
||||||
|
(Rotation.ro2cu,Rotation.cu2ro)])
|
||||||
|
def test_Rodrigues_internal(self,default,forward,backward):
|
||||||
|
cutoff = np.tan(np.pi*.5*(1.-1e-4))
|
||||||
|
for rot in default:
|
||||||
|
m = rot.as_Rodrigues()
|
||||||
|
o = backward(forward(m))
|
||||||
|
ok = np.allclose(np.clip(m,None,cutoff),np.clip(o,None,cutoff),atol=atol)
|
||||||
|
ok = ok or np.isclose(m[3],0.0,atol=atol)
|
||||||
|
print(m,o,rot.as_quaternion())
|
||||||
|
assert ok and np.isclose(np.linalg.norm(o[:3]),1.0)
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('forward,backward',[(Rotation.ho2qu,Rotation.qu2ho),
|
||||||
|
(Rotation.ho2om,Rotation.om2ho),
|
||||||
|
#(Rotation.ho2eu,Rotation.eu2ho),
|
||||||
|
(Rotation.ho2ax,Rotation.ax2ho),
|
||||||
|
(Rotation.ho2ro,Rotation.ro2ho),
|
||||||
|
(Rotation.ho2cu,Rotation.cu2ho)])
|
||||||
|
def test_homochoric_internal(self,default,forward,backward):
|
||||||
|
for rot in default:
|
||||||
|
m = rot.as_homochoric()
|
||||||
|
o = backward(forward(m))
|
||||||
|
ok = np.allclose(m,o,atol=atol)
|
||||||
|
print(m,o,rot.as_quaternion())
|
||||||
|
assert ok and np.linalg.norm(o) < (3.*np.pi/4.)**(1./3.) + 1.e-9
|
||||||
|
|
||||||
@pytest.mark.parametrize('degrees',[True,False])
|
@pytest.mark.parametrize('degrees',[True,False])
|
||||||
def test_Eulers(self,default,degrees):
|
def test_Eulers(self,default,degrees):
|
||||||
|
@ -193,7 +222,7 @@ class TestRotation:
|
||||||
if np.isclose(m[3],np.pi,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)
|
ok = ok or np.allclose(m*np.array([-1.,-1.,-1.,1.]),o,atol=atol)
|
||||||
print(m,o,rot.as_quaternion())
|
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-7
|
assert ok and np.isclose(np.linalg.norm(o[:3]),1.0) and o[3]<=np.pi+1.e-9
|
||||||
|
|
||||||
@pytest.mark.parametrize('P',[1,-1])
|
@pytest.mark.parametrize('P',[1,-1])
|
||||||
@pytest.mark.parametrize('normalise',[True,False])
|
@pytest.mark.parametrize('normalise',[True,False])
|
||||||
|
|
Loading…
Reference in New Issue