8000 Merge pull request #86 from bdaiinstitute/bokorn-bdaii/fix_log_domain · george0407/spatialmath-python@a07e74d · GitHub
[go: up one dir, main page]

Skip to content

Commit a07e74d

Browse files
Merge pull request bdaiinstitute#86 from bdaiinstitute/bokorn-bdaii/fix_log_domain
Fixed domain errors in acos near identity
2 parents 469b5fa + 02e1e90 commit a07e74d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spatialmath/base/transforms3d.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,9 @@ def trlog(
13761376
return skew(w * theta)
13771377
else:
13781378
# general case
1379-
theta = math.acos((np.trace(R) - 1) / 2)
1379+
tr = (np.trace(R) - 1) / 2
1380+
# min for inaccuracies near identity yielding trace > 3
1381+
theta = math.acos(min(tr, 1.0))
13801382
st = math.sin(theta)
13811383
if st == 0:
13821384
if twist:

tests/test_pose3d.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,18 @@ def test_functions_vect(self):
701701
# .T
702702
pass
703703

704+
def test_functions_lie(self):
705+
R = SO3.EulerVec([0.42, 0.73, -1.17])
706+
707+
# Check log and exponential map
708+
nt.assert_equal(R, SO3.Exp(R.log()))
709+
np.testing.assert_equal((R.inv() * R).log(), np.zeros([3, 3]))
710+
711+
# Check euler vector map
712+
nt.assert_equal(R, SO3.EulerVec(R.eulervec()))
713+
np.testing.assert_equal((R.inv() * R).eulervec(), np.zeros(3))
714+
715+
704716
# ============================== SE3 =====================================#
705717

706718
class TestSE3(unittest.TestCase):

0 commit comments

Comments
 (0)
0