simpler (and scipy compatible)
This commit is contained in:
parent
2d6e6a2370
commit
f4247e0f35
|
@ -253,24 +253,6 @@ class Rotation:
|
|||
return self/other
|
||||
|
||||
|
||||
def apply(self,other):
|
||||
"""
|
||||
Apply rotation to Rotation, vector, second order tensor, or fourth order tensor.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
other : Rotation or numpy.ndarray of shape (...,3), (...,3,3), or (...,3,3,3,3)
|
||||
Rotation, vector, or tensor on which to apply the rotation.
|
||||
|
||||
Returns
|
||||
-------
|
||||
rotated : Rotation or numpy.ndarray of shape (...,3), (...,3,3), or (...,3,3,3,3)
|
||||
Composed rotation or rotated vector/tensor, i.e. transformed to frame defined by rotation.
|
||||
|
||||
"""
|
||||
return self*other if isinstance(other,Rotation) else self@other
|
||||
|
||||
|
||||
def __matmul__(self,other):
|
||||
"""
|
||||
Rotation of vector, second order tensor, or fourth order tensor.
|
||||
|
@ -286,9 +268,7 @@ class Rotation:
|
|||
Rotated vector or tensor, i.e. transformed to frame defined by rotation.
|
||||
|
||||
"""
|
||||
if isinstance(other,Rotation):
|
||||
raise TypeError('Use "R1*R2", i.e. multiplication, to compose rotations "R1" and "R2"')
|
||||
elif isinstance(other,np.ndarray):
|
||||
if isinstance(other,np.ndarray):
|
||||
if self.shape + (3,) == other.shape:
|
||||
q_m = self.quaternion[...,0]
|
||||
p_m = self.quaternion[...,1:]
|
||||
|
@ -308,9 +288,13 @@ class Rotation:
|
|||
return np.einsum('...im,...jn,...ko,...lp,...mnop',R,R,R,R,other)
|
||||
else:
|
||||
raise ValueError('Can only rotate vectors, 2nd order tensors, and 4th order tensors')
|
||||
elif isinstance(other,Rotation):
|
||||
raise TypeError('Use "R1*R2", i.e. multiplication, to compose rotations "R1" and "R2"')
|
||||
else:
|
||||
raise TypeError(f'Cannot rotate {type(other)}')
|
||||
|
||||
apply = __matmul__
|
||||
|
||||
|
||||
def _standardize(self):
|
||||
"""Standardize quaternion (ensure positive real hemisphere)."""
|
||||
|
|
|
@ -1021,10 +1021,10 @@ class TestRotation:
|
|||
R = Rotation.from_random()
|
||||
assert R/R == R*R**(-1) == Rotation()
|
||||
|
||||
@pytest.mark.parametrize('item',[Rotation(),np.ones(3),np.ones((3,3)), np.ones((3,3,3,3))])
|
||||
@pytest.mark.parametrize('item',[np.ones(3),np.ones((3,3)), np.ones((3,3,3,3))])
|
||||
def test_apply(self,item):
|
||||
r = Rotation.from_random()
|
||||
assert r.apply(item) == r*item if isinstance(item,Rotation) else (r.apply(item) == r@item).all()
|
||||
assert (r.apply(item) == r@item).all()
|
||||
|
||||
@pytest.mark.parametrize('angle',[10,20,30,40,50,60,70,80,90,100,120])
|
||||
def test_average(self,angle):
|
||||
|
|
Loading…
Reference in New Issue