Skip to content

Commit 7ae7708

Browse files
committed
consistent handling of tolerance option, and add doco
1 parent 28b4d08 commit 7ae7708

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

spatialmath/base/transforms2d.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ def trinv2(T):
339339
return Ti
340340

341341

342-
def trlog2(T, check=True, twist=False):
342+
def trlog2(T, check=True, twist=False, tol=10):
343343
"""
344344
Logarithm of SO(2) or SE(2) matrix
345345
@@ -349,6 +349,8 @@ def trlog2(T, check=True, twist=False):
349349
:type check: bool
350350
:param twist: return a twist vector instead of matrix [default]
351351
:type twist: bool
352+
:param tol: Tolerance in units of eps for zero-rotation case, defaults to 10
353+
:type: float
352354
:return: logarithm
353355
:rtype: ndarray(3,3) or ndarray(3); or ndarray(2,2) or ndarray(1)
354356
:raises ValueError: bad argument
@@ -380,7 +382,7 @@ def trlog2(T, check=True, twist=False):
380382
if ishom2(T, check=check):
381383
# SE(2) matrix
382384

383-
if smb.iseye(T):
385+
if smb.iseye(T, tol):
384386
# is identity matrix
385387
if twist:
386388
return np.zeros((3,))

spatialmath/base/transforms3d.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ def ishom(T, check=False, tol=100):
323323
:type T: numpy(4,4)
324324
:param check: check validity of rotation submatrix
325325
:type check: bool
326+
:param tol: Tolerance in units of eps for rotation submatrix check, defaults to 100
327+
:type: float
326328
:return: whether matrix is an SE(3) homogeneous transformation matrix
327329
:rtype: bool
328330
@@ -365,6 +367,8 @@ def isrot(R, check=False, tol=100):
365367
:type R: numpy(3,3)
366368
:param check: check validity of rotation submatrix
367369
:type check: bool
370+
:param tol: Tolerance in units of eps for rotation matrix test, defaults to 100
371+
:type: float
368372
:return: whether matrix is an SO(3) rotation matrix
369373
:rtype: bool
370374
@@ -1142,7 +1146,7 @@ def tr2rpy(T, unit="rad", order="zyx", check=False):
11421146

11431147

11441148
# ---------------------------------------------------------------------------------------#
1145-
def trlog(T, check=True, twist=False):
1149+
def trlog(T, check=True, twist=False, tol=10):
11461150
"""
11471151
Logarithm of SO(3) or SE(3) matrix
11481152
@@ -1152,6 +1156,8 @@ def trlog(T, check=True, twist=False):
11521156
:type check: bool
11531157
:param twist: return a twist vector instead of matrix [default]
11541158
:type twist: bool
1159+
:param tol: Tolerance in units of eps for zero-rotation case, defaults to 10
1160+
:type: float
11551161
:return: logarithm
11561162
:rtype: ndarray(4,4) or ndarray(3,3)
11571163
:raises ValueError: bad argument
@@ -1179,10 +1185,10 @@ def trlog(T, check=True, twist=False):
11791185
:seealso: :func:`~trexp` :func:`~spatialmath.smb.transformsNd.vex` :func:`~spatialmath.smb.transformsNd.vexa`
11801186
"""
11811187

1182-
if ishom(T, check=check):
1188+
if ishom(T, check=check, tol=10):
11831189
# SE(3) matrix
11841190

1185-
if smb.iseye(T):
1191+
if smb.iseye(T, tol=tol):
11861192
# is identity matrix
11871193
if twist:
11881194
return np.zeros((6,))
@@ -1221,7 +1227,7 @@ def trlog(T, check=True, twist=False):
12211227
return np.zeros((3,))
12221228
else:
12231229
return np.zeros((3, 3))
1224-
elif abs(np.trace(R) + 1) < 100 * _eps:
1230+
elif abs(np.trace(R) + 1) < tol * _eps:
12251231
# check for trace = -1
12261232
# rotation by +/- pi, +/- 3pi etc.
12271233
diagonal = R.diagonal()

0 commit comments

Comments
 (0)