Package geometry :: Package manifolds :: Module special_orthogonal_algebra
[hide private]
[frames] | no frames]

Source Code for Module geometry.manifolds.special_orthogonal_algebra

 1  from . import np, MatrixLieAlgebra, contract 
 2  from .. import hat_map, hat_map_2d, map_hat_2d, map_hat 
3 4 5 -class so_algebra(MatrixLieAlgebra):
6 ''' 7 This is the Lie algebra of skew-symmetric matrices so(n), 8 for the Special Orthogonal group SO(n). 9 ''' 10
11 - def __init__(self, n):
12 dimension = {2: 1, 3: 3}[n] 13 MatrixLieAlgebra.__init__(self, n=n, dimension=dimension)
14
15 - def project(self, v):
16 ''' Projects *v* to the closest skew-symmetric matrix. ''' 17 return 0.5 * (v - v.T)
18
19 - def __repr__(self):
20 return 'so%s' % (self.n)
21
22 - def interesting_points(self):
23 points = [] 24 points.append(self.zero()) 25 if self.n == 2: 26 points.append(hat_map_2d(np.pi)) 27 points.append(hat_map_2d(np.pi / 2)) 28 points.append(hat_map_2d(-np.pi)) 29 elif self.n == 3: 30 points.append(hat_map(np.array([0, 0, 1]) * np.pi / 2)) 31 points.append(hat_map(np.array([0, 0, 1]) * np.pi)) 32 points.append(hat_map(np.array([0, 1, 0]) * np.pi / 2)) 33 points.append(hat_map(np.array([0, 1, 0]) * np.pi)) 34 points.append(hat_map(np.array([1, 0, 0]) * np.pi / 2)) 35 points.append(hat_map(np.array([1, 0, 0]) * np.pi)) 36 else: 37 assert False, 'Not implemented for n=%s' % self.n 38 return points
39 40 @contract(a='belongs')
41 - def vector_from_algebra(self, a):
42 if self.n == 2: 43 return np.array([map_hat_2d(a)]) 44 elif self.n == 3: 45 return map_hat(a) 46 else: 47 assert False, 'Not implemented for n=%s.' % self.n
48 49 @contract(v='array[N]')
50 - def algebra_from_vector(self, v):
51 if self.n == 2: 52 return hat_map_2d(v[0]) 53 elif self.n == 3: 54 return hat_map(v) 55 else: 56 assert False, 'Not implemented for n=%s.' % self.n
57