def export(self, to='rotmat'): ''' Conversion to other formats. May be slow for "Fick", "Helmholtz", and "Euler". Parameters ---------- to : string content of returned values * 'rotmat' : rotation matrices (default), each flattened to a 9-dim vector * 'Euler' : Euler angles * 'Fick' : Fick angles * 'Helmholtz' : Helmholtz angles * 'vector' : vector part of the quaternion Returns ------- ndarray, with the specified content Examples -------- >>> q = Quaternion([0,0.2,0.1]) >>> rm = q.export() >>> fick = q.export('Fick') ''' if to.lower() == 'rotmat' : return convert(self.values, 'rotmat') if to.lower() == 'vector' : return self.values[:,1:] if to.lower() == 'euler': Euler = np.zeros((len(self),3)) rm = self.export() if rm.shape == (3,3): rm = rm.reshape((1,9)) for ii in range(len(self)): Euler[ii,:] = rotmat.rotmat2Euler(rm[ii].reshape((3,3))) return Euler if to.lower() == 'fick': Fick = np.zeros((len(self),3)) rm = self.export() if rm.shape == (3,3): rm = rm.reshape((1,9)) for ii in range(len(self)): Fick[ii,:] = rotmat.rotmat2Fick(rm[ii].reshape((3,3))) return Fick if to.lower() == 'helmholtz': Helmholtz = np.zeros((len(self),3)) rm = self.export() if rm.shape == (3,3): rm = rm.reshape((1,9)) for ii in range(len(self)): Helmholtz[ii,:] = rotmat.rotmat2Helmholtz(rm[ii].reshape((3,3))) return Helmholtz
def test_Euler(self): testmat = np.array([[np.sqrt(2)/2, -np.sqrt(2)/2, 0], [np.sqrt(2)/2, np.sqrt(2)/2, 0], [0, 0, 1]]) Euler = rotmat.rotmat2Euler(testmat) correct = np.r_[[np.pi/4,0,0]] self.assertAlmostEqual(np.linalg.norm(correct - np.array(Euler)), 0)
def export(self, to='rotmat'): ''' Conversion to other formats. May be slow for "Fick", "Helmholtz", and "Euler". Parameters ---------- to : string content of returned values * 'rotmat' : rotation matrices (default), each flattened to a 9-dim vector * 'Euler' : Euler angles * 'Fick' : Fick angles * 'Helmholtz' : Helmholtz angles * 'vector' : vector part of the quaternion Returns ------- ndarray, with the specified content Examples -------- >>> q = Quaternion([0,0.2,0.1]) >>> rm = q.export() >>> fick = q.export('Fick') ''' if to.lower() == 'rotmat': return convert(self.values, 'rotmat') if to.lower() == 'vector': return self.values[:, 1:] if to.lower() == 'euler': Euler = np.zeros((len(self), 3)) rm = self.export() if rm.shape == (3, 3): rm = rm.reshape((1, 9)) for ii in range(len(self)): Euler[ii, :] = rotmat.rotmat2Euler(rm[ii].reshape((3, 3))) return Euler if to.lower() == 'fick': Fick = np.zeros((len(self), 3)) rm = self.export() if rm.shape == (3, 3): rm = rm.reshape((1, 9)) for ii in range(len(self)): Fick[ii, :] = rotmat.rotmat2Fick(rm[ii].reshape((3, 3))) return Fick if to.lower() == 'helmholtz': Helmholtz = np.zeros((len(self), 3)) rm = self.export() if rm.shape == (3, 3): rm = rm.reshape((1, 9)) for ii in range(len(self)): Helmholtz[ii, :] = rotmat.rotmat2Helmholtz(rm[ii].reshape( (3, 3))) return Helmholtz
def test_Euler(self): testmat = np.array([[np.sqrt(2) / 2, -np.sqrt(2) / 2, 0], [np.sqrt(2) / 2, np.sqrt(2) / 2, 0], [0, 0, 1]]) Euler = rotmat.rotmat2Euler(testmat) correct = np.r_[[np.pi / 4, 0, 0]] self.assertAlmostEqual(np.linalg.norm(correct - np.array(Euler)), 0)