9 """ 2 dimensional group of orthogonal matrices with determinant 1 """
12 """ internally represented by a unit complex number z """
17 """ exponential map """
24 """ logarithmic map"""
25 return sympy.atan2(self.
z.imag, self.
z.real)
28 return "So2:" + repr(self.
z)
32 return sympy.Matrix([[0, -theta],
36 """ returns matrix representation """
38 [self.
z.real, -self.
z.imag],
39 [self.
z.imag, self.
z.real]])
42 """ left-multiplication
43 either rotation concatenation or point-transform """
44 if isinstance(right, sympy.Matrix):
45 assert right.shape == (2, 1), right.shape
46 return self.
matrix() * right
47 elif isinstance(right, So2):
48 return So2(self.
z * right.z)
49 assert False,
"unsupported type: {0}".format(type(right))
56 return sympy.Matrix(2, 1,
lambda r, c:
57 sympy.diff(So2.exp(x)[r], x))
61 return sympy.Matrix([0, 1])
65 return So2.calc_Dx_exp_x(x).limit(x, 0)
68 return sympy.Matrix(2, 1,
lambda r, c:
69 sympy.diff((self * So2.exp(x))[r], x))\
75 return sympy.Matrix([[1, 0],
78 return sympy.Matrix([[0, -1],
83 return sympy.Matrix(2, 2,
lambda r, c:
84 sympy.diff(x.matrix()[r, c], x[i]))
89 Dx_exp_x = So2.calc_Dx_exp_x(x)
90 l = [Dx_exp_x[j] * So2.Dxi_x_matrix(R, j)
for j
in [0, 1]]
91 return functools.reduce((
lambda a, b: a + b), l)
95 return sympy.Matrix(2, 2,
lambda r, c:
96 sympy.diff(So2.exp(x).
matrix()[r, c], x))
104 return sympy.Matrix(2, 2,
lambda r, c:
105 sympy.diff(So2.exp(x).
matrix()[r, c], x)
113 x, y = sympy.symbols(
'c[0] c[1]', real=
True)
114 p0, p1 = sympy.symbols(
'p0 p1', real=
True)
116 self.
p = sophus.Vector2(p0, p1)
119 for theta
in [0., 0.5, 0.1]:
120 w = So2.exp(theta).log()
121 self.assertAlmostEqual(theta, w)
124 R_foo_bar = So2.exp(self.
theta)
125 Rmat_foo_bar = R_foo_bar.matrix()
127 p1_foo = R_foo_bar * point_bar
128 p2_foo = Rmat_foo_bar * point_bar
129 self.assertEqual(sympy.simplify(p1_foo - p2_foo),
130 sophus.ZeroVector2())
133 self.assertEqual(sympy.simplify(So2.calc_Dx_exp_x_at_0(self.
theta) -
134 So2.Dx_exp_x_at_0()),
135 sympy.Matrix.zeros(2, 1))
137 self.assertEqual(sympy.simplify(So2.calc_Dxi_x_matrix(self.
a, i) -
138 So2.Dxi_x_matrix(self.
a, i)),
139 sympy.Matrix.zeros(2, 2))
141 self.assertEqual(sympy.simplify(
142 So2.Dx_exp_x_matrix(self.
theta) -
143 So2.calc_Dx_exp_x_matrix(self.
theta)),
144 sympy.Matrix.zeros(2, 2))
145 self.assertEqual(sympy.simplify(
146 So2.Dx_exp_x_matrix_at_0() -
147 So2.calc_Dx_exp_x_matrix_at_0(self.
theta)),
148 sympy.Matrix.zeros(2, 2))
152 filename =
"cpp_gencode/So2_Dx_exp_x.cpp"
155 file = open(filename,
"w")
160 file = open(filename,
"r")
161 file_lines = file.readlines()
162 for i, line
in enumerate(stream):
163 self.assertEqual(line, file_lines[i])
168 self.
a.calc_Dx_this_mul_exp_x_at_0(self.
theta))
169 filename =
"cpp_gencode/So2_Dx_this_mul_exp_x_at_0.cpp"
172 file = open(filename,
"w")
177 file = open(filename,
"r")
178 file_lines = file.readlines()
179 for i, line
in enumerate(stream):
180 self.assertEqual(line, file_lines[i])
185 if __name__ ==
'__main__':