@@ -142,12 +142,14 @@ def colvec(v: ArrayLike) -> NDArray:
142142 return np .array (v ).reshape ((len (v ), 1 ))
143143
144144
145- def unitvec (v : ArrayLike ) -> NDArray :
145+ def unitvec (v : ArrayLike , tol : float = 100 ) -> NDArray :
146146 """
147147 Create a unit vector
148148
149149 :param v: any vector
150150 :type v: array_like(n)
151+ :param tol: Tolerance in units of eps for zero-norm case, defaults to 100
152+ :type: float
151153 :return: a unit-vector parallel to ``v``.
152154 :rtype: ndarray(n)
153155 :raises ValueError: for zero length vector
@@ -166,7 +168,7 @@ def unitvec(v: ArrayLike) -> NDArray:
166168 v = getvector (v )
167169 n = norm (v )
168170
169- if n > 100 * _eps : # if greater than eps
171+ if n > tol * _eps : # if greater than eps
170172 return v / n
171173 else :
172174 raise ValueError ("zero norm vector" )
@@ -178,6 +180,8 @@ def unitvec_norm(v: ArrayLike, tol: float = 100) -> Tuple[NDArray, float]:
178180
179181 :param v: any vector
180182 :type v: array_like(n)
183+ :param tol: Tolerance in units of eps for zero-norm case, defaults to 100
184+ :type: float
181185 :return: a unit-vector parallel to ``v`` and the norm
182186 :rtype: (ndarray(n), float)
183187 :raises ValueError: for zero length vector
@@ -208,7 +212,7 @@ def isunitvec(v: ArrayLike, tol: float = 10) -> bool:
208212
209213 :param v: vector to test
210214 :type v: ndarray(n)
211- :param tol: tolerance in units of eps
215+ :param tol: tolerance in units of eps, defaults to 10
212216 :type tol: float
213217 :return: whether vector has unit length
214218 :rtype: bool
@@ -230,7 +234,7 @@ def iszerovec(v: ArrayLike, tol: float = 10) -> bool:
230234
231235 :param v: vector to test
232236 :type v: ndarray(n)
233- :param tol: tolerance in units of eps
237+ :param tol: tolerance in units of eps, defaults to 10
234238 :type tol: float
235239 :return: whether vector has zero length
236240 :rtype: bool
@@ -252,7 +256,7 @@ def iszero(v: float, tol: float = 10) -> bool:
252256
253257 :param v: value to test
254258 :type v: float
255- :param tol: tolerance in units of eps
259+ :param tol: tolerance in units of eps, defaults to 10
256260 :type tol: float
257261 :return: whether value is zero
258262 :rtype: bool
@@ -274,7 +278,7 @@ def isunittwist(v: ArrayLike6, tol: float = 10) -> bool:
274278
275279 :param v: twist vector to test
276280 :type v: array_like(6)
277- :param tol: tolerance in units of eps
281+ :param tol: tolerance in units of eps, defaults to 10
278282 :type tol: float
279283 :return: whether twist has unit length
280284 :rtype: bool
@@ -302,7 +306,7 @@ def isunittwist(v: ArrayLike6, tol: float = 10) -> bool:
302306 if len (v ) == 6 :
303307 # test for SE(3) twist
304308 return isunitvec (v [3 :6 ], tol = tol ) or (
305- bool ( np . linalg . norm ( v [3 :6 ]) < tol * _eps ) and isunitvec (v [0 :3 ], tol = tol )
309+ iszerovec ( v [3 :6 ], tol = tol ) and isunitvec (v [0 :3 ], tol = tol )
306310 )
307311 else :
308312 raise ValueError
@@ -314,7 +318,7 @@ def isunittwist2(v: ArrayLike3, tol: float = 10) -> bool:
314318
315319 :param v: twist vector to test
316320 :type v: array_like(3)
317- :param tol: tolerance in units of eps
321+ :param tol: tolerance in units of eps, defaults to 10
318322 :type tol: float
319323 :return: whether vector has unit length
320324 :rtype: bool
@@ -341,7 +345,7 @@ def isunittwist2(v: ArrayLike3, tol: float = 10) -> bool:
341345 if len (v ) == 3 :
342346 # test for SE(2) twist
343347 return isunitvec (v [2 ], tol = tol ) or (
344- np . abs (v [2 ]) < tol * _eps and isunitvec (v [0 :2 ], tol = tol )
348+ iszero (v [2 ], tol = tol ) and isunitvec (v [0 :2 ], tol = tol )
345349 )
346350 else :
347351 raise ValueError
@@ -353,7 +357,7 @@ def unittwist(S: ArrayLike6, tol: float = 10) -> Union[R6, None]:
353357
354358 :param S: twist vector
355359 :type S: array_like(6)
356- :param tol: tolerance in units of eps
360+ :param tol: tolerance in units of eps, defaults to 10
357361 :type tol: float
358362 :return: unit twist
359363 :rtype: ndarray(6)
@@ -380,7 +384,7 @@ def unittwist(S: ArrayLike6, tol: float = 10) -> Union[R6, None]:
380384 v = S [0 :3 ]
381385 w = S [3 :6 ]
382386
383- if iszerovec (w ):
387+ if iszerovec (w , tol = tol ):
384388 th = norm (v )
385389 else :
386390 th = norm (w )
@@ -394,7 +398,7 @@ def unittwist_norm(S: Union[R6, ArrayLike6], tol: float = 10) -> Tuple[R6, float
394398
395399 :param S: twist vector
396400 :type S: array_like(6)
397- :param tol: tolerance in units of eps
401+ :param tol: tolerance in units of eps, defaults to 10
398402 :type tol: float
399403 :return: unit twist and scalar motion
400404 :rtype: tuple (ndarray(6), float)
@@ -425,20 +429,22 @@ def unittwist_norm(S: Union[R6, ArrayLike6], tol: float = 10) -> Tuple[R6, float
425429 v = S [0 :3 ]
426430 w = S [3 :6 ]
427431
428- if iszerovec (w ):
432+ if iszerovec (w , tol = tol ):
429433 th = norm (v )
430434 else :
431435 th = norm (w )
432436
433437 return (S / th , th )
434438
435439
436- def unittwist2 (S : ArrayLike3 ) -> R3 :
440+ def unittwist2 (S : ArrayLike3 , tol : float = 10 ) -> R3 :
437441 """
438442 Convert twist to unit twist
439443
440444 :param S: twist vector
441445 :type S: array_like(3)
446+ :param tol: tolerance in units of eps, defaults to 10
447+ :type tol: float
442448 :return: unit twist
443449 :rtype: ndarray(3)
444450
@@ -459,20 +465,22 @@ def unittwist2(S: ArrayLike3) -> R3:
459465 v = S [0 :2 ]
460466 w = S [2 ]
461467
462- if iszero (w ):
468+ if iszero (w , tol = tol ):
463469 th = norm (v )
464470 else :
465471 th = abs (w )
466472
467473 return S / th
468474
469475
470- def unittwist2_norm (S : ArrayLike3 ) -> Tuple [R3 , float ]:
476+ def unittwist2_norm (S : ArrayLike3 , tol : float = 10 ) -> Tuple [R3 , float ]:
471477 """
472478 Convert twist to unit twist
473479
474480 :param S: twist vector
475481 :type S: array_like(3)
482+ :param tol: tolerance in units of eps, defaults to 10
483+ :type tol: float
476484 :return: unit twist and scalar motion
477485 :rtype: tuple (ndarray(3), float)
478486
@@ -493,7 +501,7 @@ def unittwist2_norm(S: ArrayLike3) -> Tuple[R3, float]:
493501 v = S [0 :2 ]
494502 w = S [2 ]
495503
496- if iszero (w ):
504+ if iszero (w , tol = tol ):
497505 th = norm (v )
498506 else :
499507 th = abs (w )
0 commit comments