|
| 1 | +import numpy.testing as nt |
| 2 | +import unittest |
| 3 | + |
| 4 | +""" |
| 5 | +we will assume that the primitives rotx,trotx, etc. all work |
| 6 | +""" |
| 7 | +from spatialmath import SE3, SO3, SE2 |
| 8 | +import numpy as np |
| 9 | +import spatialmath.base.transforms3d as t3d |
| 10 | + |
| 11 | + |
| 12 | +class TestTransforms3D(unittest.TestCase): |
| 13 | + @classmethod |
| 14 | + def tearDownClass(cls): |
| 15 | + pass |
| 16 | + |
| 17 | + def test_tr2angvec(self): |
| 18 | + true_ang = 1.51 |
| 19 | + true_vec = np.array([0., 1., 0.]) |
| 20 | + eps = 1e-08 |
| 21 | + |
| 22 | + # show that tr2angvec works on true rotation matrix |
| 23 | + R = SO3.Ry(true_ang) |
| 24 | + ang, vec = t3d.tr2angvec(R.A, check=True) |
| 25 | + nt.assert_equal(ang, true_ang) |
| 26 | + nt.assert_equal(vec, true_vec) |
| 27 | + |
| 28 | + # check a rotation matrix that should fail |
| 29 | + badR = SO3.Ry(true_ang).A[:, :] + eps |
| 30 | + with self.assertRaises(ValueError): |
| 31 | + t3d.tr2angvec(badR, check=True) |
| 32 | + |
| 33 | + # run without check |
| 34 | + ang, vec = t3d.tr2angvec(badR, check=False) |
| 35 | + nt.assert_almost_equal(ang, true_ang) |
| 36 | + nt.assert_equal(vec, true_vec) |
| 37 | + |
| 38 | + |
| 39 | +# ---------------------------------------------------------------------------------------# |
| 40 | +if __name__ == '__main__': |
| 41 | + |
| 42 | + unittest.main() |
0 commit comments