simplified

This commit is contained in:
Martin Diehl 2021-01-13 09:50:58 +01:00
parent f4247e0f35
commit 196902948f
1 changed files with 13 additions and 25 deletions

View File

@ -70,17 +70,9 @@ class Rotation:
def __repr__(self): def __repr__(self):
"""Represent rotation as unit quaternion, rotation matrix, and Bunge-Euler angles.""" """Represent rotation as unit quaternion(s)."""
if self.shape == () and self == Rotation(): return f'Quaternion{" " if self.quaternion.shape == (4,) else "s of shape "+str(self.quaternion.shape)+chr(10)}'\
return 'Rotation()' + str(self.quaternion)
else:
return f'Quaternions {self.shape}:\n'+str(self.quaternion) \
if self.quaternion.shape != (4,) else \
'\n'.join([
'Quaternion: (real={:.3f}, imag=<{:+.3f}, {:+.3f}, {:+.3f}>)'.format(*(self.quaternion)),
'Matrix:\n{}'.format(np.round(self.as_matrix(),8)),
'Bunge Eulers / deg: ({:3.2f}, {:3.2f}, {:3.2f})'.format(*self.as_Euler_angles(degrees=True)),
])
def __copy__(self,**kwargs): def __copy__(self,**kwargs):
@ -150,35 +142,31 @@ class Rotation:
return dup return dup
def __pow__(self,pwr): def __pow__(self,exp):
""" """
Raise quaternion to power. Perform the rotation 'exp' times.
Equivalent to performing the rotation 'pwr' times.
Parameters Parameters
---------- ----------
pwr : float exp : float
Power to raise quaternion to. Exponent.
""" """
phi = np.arccos(self.quaternion[...,0:1]) phi = np.arccos(self.quaternion[...,0:1])
p = self.quaternion[...,1:]/np.linalg.norm(self.quaternion[...,1:],axis=-1,keepdims=True) p = self.quaternion[...,1:]/np.linalg.norm(self.quaternion[...,1:],axis=-1,keepdims=True)
return self.copy(rotation=Rotation(np.block([np.cos(pwr*phi),np.sin(pwr*phi)*p]))._standardize()) return self.copy(rotation=Rotation(np.block([np.cos(exp*phi),np.sin(exp*phi)*p]))._standardize())
def __ipow__(self,pwr): def __ipow__(self,exp):
""" """
Raise quaternion to power (in-place). Perform the rotation 'exp' times (in-place).
Equivalent to performing the rotation 'pwr' times.
Parameters Parameters
---------- ----------
pwr : float exp : float
Power to raise quaternion to. Exponent.
""" """
return self**pwr return self**exp
def __mul__(self,other): def __mul__(self,other):