test-matrix-util.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import unittest
4 
5 import numpy as np
7 
8 
9 class MatrixUtilTest(unittest.TestCase):
11  mat = ((1, 2), (3, 4))
12  self.assertEqual(mat, mod.matrixToTuple(np.matrix(mat)))
13 
15  mat = ((1, 2), (3, 4))
16  self.assertEqual(mat, mod.matrixToTuple(np.array(mat)))
17 
19  vec = (1, 2, 3, 4)
20  self.assertEqual(vec, mod.vectorToTuple(np.matrix(vec)))
21  self.assertEqual(vec, mod.vectorToTuple(np.array(vec)))
22 
23  def test_rpy_tr(self):
24  for rpy, tr in [
25  ((0, 0, 0), mod.matrixToTuple(np.identity(4))),
26  ((np.pi, 0, 0), ((1, 0, 0, 0), (0, -1, 0, 0), (0, 0, -1, 0), (0, 0, 0, 1))),
27  ((0, np.pi, 0), ((-1, 0, 0, 0), (0, 1, 0, 0), (0, 0, -1, 0), (0, 0, 0, 1))),
28  ((0, 0, np.pi), ((-1, 0, 0, 0), (0, -1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))),
29  ]:
30  np.testing.assert_allclose(tr, mod.rpy2tr(*rpy), atol=1e-15)
31 
32  def test_matrix_rpy(self):
33  for mat, rpy in [
34  (mod.matrixToTuple(np.identity(4)), (0, 0, 0, 0, 0, 0)),
35  (mod.matrixToTuple(-np.identity(4)), (0, 0, 0, -np.pi, 0, -np.pi)),
36  ]:
37  np.testing.assert_allclose(rpy, mod.matrixToRPY(mat))
38  # np.testing.assert_allclose(mat, mod.RPYToMatrix(rpy))
39  np.testing.assert_allclose(rpy, mod.matrixToRPY(mod.RPYToMatrix(rpy)))
40 
41  def test_rotate(self):
42  for axis, angle, mat in [
43  (
44  "x",
45  np.pi,
46  ((1, 0, 0, 0), (0, -1, 0, 0), (0, 0, -1, 0), (0, 0, 0, 1)),
47  ),
48  (
49  "y",
50  np.pi,
51  ((-1, 0, 0, 0), (0, 1, 0, 0), (0, 0, -1, 0), (0, 0, 0, 1)),
52  ),
53  (
54  "z",
55  np.pi,
56  ((-1, 0, 0, 0), (0, -1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)),
57  ),
58  ]:
59  self.assertEqual(mat, mod.rotate(axis, angle))
60 
61  def test_quat_mat(self):
62  for quat, mat in [
63  ((0, 0, 0, 1), np.identity(3)),
64  ((0, 0, 1, 0), ((-1, 0, 0), (0, -1, 0), (0, 0, 1))),
65  ((0, -0.5, 0, 0.5), ((0.5, 0, -0.5), (0, 1, 0), (0.5, 0, 0.5))),
66  ]:
67  self.assertEqual(mat, mod.quaternionToMatrix(quat))
68 
69 
70 if __name__ == "__main__":
71  unittest.main()
test-matrix-util.MatrixUtilTest.test_matrix_rpy
def test_matrix_rpy(self)
Definition: test-matrix-util.py:32
test-matrix-util.MatrixUtilTest.test_matrix_to_tuple
def test_matrix_to_tuple(self)
Definition: test-matrix-util.py:10
test-matrix-util.MatrixUtilTest.test_vector_to_tuple
def test_vector_to_tuple(self)
Definition: test-matrix-util.py:18
test-matrix-util.MatrixUtilTest
Definition: test-matrix-util.py:9
test-matrix-util.MatrixUtilTest.test_rpy_tr
def test_rpy_tr(self)
Definition: test-matrix-util.py:23
test-matrix-util.MatrixUtilTest.test_array_to_tuple
def test_array_to_tuple(self)
Definition: test-matrix-util.py:14
dynamic_graph.sot.core.matrix_util
Definition: matrix_util.py:1


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:32