From 84614a205d11d7290141065689a0bd951249cf8b Mon Sep 17 00:00:00 2001 From: Mark Yeatman <129521731+myeatman-bdai@users.noreply.github.com> Date: Wed, 6 Dec 2023 11:48:57 -0500 Subject: [PATCH] Fix isR to catch reflections. (#110) --- spatialmath/base/transformsNd.py | 2 +- tests/base/test_transforms3d.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/spatialmath/base/transformsNd.py b/spatialmath/base/transformsNd.py index 57476d05..c04e5d8b 100644 --- a/spatialmath/base/transformsNd.py +++ b/spatialmath/base/transformsNd.py @@ -380,7 +380,7 @@ def isR(R: NDArray, tol: float = 20) -> bool: # -> TypeGuard[SOnArray]: """ return bool( np.linalg.norm(R @ R.T - np.eye(R.shape[0])) < tol * _eps - and np.linalg.det(R @ R.T) > 0 + and np.linalg.det(R) > 0 ) diff --git a/tests/base/test_transforms3d.py b/tests/base/test_transforms3d.py index f7eb5248..2f1e6049 100755 --- a/tests/base/test_transforms3d.py +++ b/tests/base/test_transforms3d.py @@ -61,6 +61,14 @@ def test_checks(self): nt.assert_equal(isrot(T, True), False) nt.assert_equal(ishom(T, True), False) + # reflection case + T = np.array([[-1, 0, 0], [0, 1, 0], [0, 0, 1]]) + nt.assert_equal(isR(T), False) + nt.assert_equal(isrot(T), True) + nt.assert_equal(ishom(T), False) + nt.assert_equal(isrot(T, True), False) + nt.assert_equal(ishom(T, True), False) + def test_trinv(self): T = np.eye(4) nt.assert_array_almost_equal(trinv(T), T)