8000 fix bugs in iseye and unittwist2 · suddrey-qut/spatialmath-python@9cd9b47 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cd9b47

Browse files
committed
fix bugs in iseye and unittwist2
1 parent b2912e8 commit 9cd9b47

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

spatialmath/base/transformsNd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def iseye(S, tol=10):
398398
s = S.shape
399399
if len(s) != 2 or s[0] != s[1]:
400400
return False # not a square matrix
401-
return base.norm(S - np.eye(s[0])) < tol * _eps
401+
return np.linalg.norm(S - np.eye(s[0])) < tol * _eps
402402

403403

404404
# ---------------------------------------------------------------------------------------#

spatialmath/base/vectors.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def isunitvec(v, tol=10):
216216
>>> isunitvec([1, 0])
217217
>>> isunitvec([1, 2])
218218
219-
:seealso: unit, isunittwist
219+
:seealso: unit, iszerovec, isunittwist
220220
"""
221221
return abs(np.linalg.norm(v) - 1) < tol * _eps
222222

@@ -235,13 +235,33 @@ def iszerovec(v, tol=10):
235235
.. runblock:: pycon
236236
237237
>>> from spatialmath.base import *
238-
>>> isunit([0, 0])
239-
>>> isunit([1, 2])
238+
>>> iszerovec([0, 0])
239+
>>> iszerovec([1, 2])
240240
241-
:seealso: unit, isunittwist
241+
:seealso: unit, isunitvec, isunittwist
242242
"""
243243
return np.linalg.norm(v) < tol * _eps
244244

245+
def iszero(v, tol=10):
246+
"""
247+
Test if scalar is zero
248+
249+
:param v: value to test
250+
:type v: float
251+
:param tol: tolerance in units of eps
252+
:type tol: float
253+
:return: whether value is zero
254+
:rtype: bool
255+
256+
.. runblock:: pycon
257+
258+
>>> from spatialmath.base import *
259+
>>> iszero(0)
260+
>>> iszero(1)
261+
262+
:seealso: unit, iszerovec, isunittwist
263+
"""
264+
return abs(v) < tol * _eps
245265

246266
def isunittwist(v, tol=10):
247267
r"""
@@ -430,10 +450,10 @@ def unittwist2(S):
430450
v = S[0:2]
431451
w = S[2]
432452

433-
if iszerovec(w):
453+
if iszero(w):
434454
th = norm(v)
435455
else:
436-
th = norm(w)
456+
th = abs(w)
437457

438458
return S / th
439459

@@ -463,10 +483,10 @@ def unittwist2_norm(S):
463483
v = S[0:2]
464484
w = S[2]
465485

466-
if iszerovec(w):
486+
if iszero(w):
467487
th = norm(v)
468488
else:
469-
th = norm(w)
489+
th = abs(w)
470490

471491
return (S / th, th)
472492

0 commit comments

Comments
 (0)
0