@@ -713,7 +713,7 @@ def eul2tr(
713713# ---------------------------------------------------------------------------------------#
714714
715715
716- def angvec2r (theta : float , v : ArrayLike3 , unit = "rad" ) -> SO3Array :
716+ def angvec2r (theta : float , v : ArrayLike3 , unit = "rad" , tol : float = 10 ) -> SO3Array :
717717 """
718718 Create an SO(3) rotation matrix from rotation angle and axis
719719
@@ -723,6 +723,8 @@ def angvec2r(theta: float, v: ArrayLike3, unit="rad") -> SO3Array:
723723 :type unit: str
724724 :param v: 3D rotation axis
725725 :type v: array_like(3)
726+ :param tol: Tolerance in units of eps for zero-rotation case, defaults to 10
727+ :type: float
726728 :return: SO(3) rotation matrix
727729 :rtype: ndarray(3,3)
728730 :raises ValueError: bad arguments
@@ -748,7 +750,7 @@ def angvec2r(theta: float, v: ArrayLike3, unit="rad") -> SO3Array:
748750 if not isscalar (theta ) or not isvector (v , 3 ):
749751 raise ValueError ("Arguments must be angle and vector" )
750752
751- if np .linalg .norm (v ) < 10 * _eps :
753+ if np .linalg .norm (v ) < tol * _eps :
752754 return np .eye (3 )
753755
754756 θ = getunit (theta , unit )
@@ -1044,6 +1046,7 @@ def tr2eul(
10441046 unit : str = "rad" ,
10451047 flip : bool = False ,
10461048 check : bool = False ,
1049+ tol : float = 10 ,
10471050) -> R3 :
10481051 r"""
10491052 Convert SO(3) or SE(3) to ZYX Euler angles
@@ -1056,6 +1059,8 @@ def tr2eul(
10561059 :type flip: bool
10571060 :param check: check that rotation matrix is valid
10581061 :type check: bool
1062+ :param tol: Tolerance in units of eps for near-zero checks, defaults to 10
1063+ :type: float
10591064 :return: ZYZ Euler angles
10601065 :rtype: ndarray(3)
10611066
@@ -1090,11 +1095,11 @@ def tr2eul(
10901095 R = t2r (T )
10911096 else :
10921097 R = T
1093- if not isrot (R , check = check ):
1098+ if not isrot (R , check = check , tol = tol ):
10941099 raise ValueError ("argument is not SO(3)" )
10951100
10961101 eul = np .zeros ((3 ,))
1097- if abs (R [0 , 2 ]) < 10 * _eps and abs (R [1 , 2 ]) < 10 * _eps :
1102+ if abs (R [0 , 2 ]) < tol * _eps and abs (R [1 , 2 ]) < tol * _eps :
10981103 eul [0 ] = 0
10991104 sp = 0
11001105 cp = 1
@@ -1124,6 +1129,7 @@ def tr2rpy(
11241129 unit : str = "rad" ,
11251130 order : str = "zyx" ,
11261131 check : bool = False ,
1132+ tol : float = 10 ,
11271133) -> R3 :
11281134 r"""
11291135 Convert SO(3) or SE(3) to roll-pitch-yaw angles
@@ -1136,6 +1142,8 @@ def tr2rpy(
11361142 :type order: str
11371143 :param check: check that rotation matrix is valid
11381144 :type check: bool
1145+ :param tol: Tolerance in units of eps, defaults to 10
1146+ :type: float
11391147 :return: Roll-pitch-yaw angles
11401148 :rtype: ndarray(3)
11411149 :raises ValueError: bad arguments
@@ -1176,13 +1184,13 @@ def tr2rpy(
11761184 R = t2r (T )
11771185 else :
11781186 R = T
1179- if not isrot (R , check = check ):
1187+ if not isrot (R , check = check , tol = tol ):
11801188 raise ValueError ("not a valid SO(3) matrix" )
11811189
11821190 rpy = np .zeros ((3 ,))
11831191 if order in ("xyz" , "arm" ):
11841192 # XYZ order
1185- if abs (abs (R [0 , 2 ]) - 1 ) < 10 * _eps : # when |R13| == 1
1193+ if abs (abs (R [0 , 2 ]) - 1 ) < tol * _eps : # when |R13| == 1
11861194 # singularity
11871195 rpy [0 ] = 0 # roll is zero
11881196 if R [0 , 2 ] > 0 :
@@ -1206,7 +1214,7 @@ def tr2rpy(
12061214
12071215 elif order in ("zyx" , "vehicle" ):
12081216 # old ZYX order (as per Paul book)
1209- if abs (abs (R [2 , 0 ]) - 1 ) < 10 * _eps : # when |R31| == 1
1217+ if abs (abs (R [2 , 0 ]) - 1 ) < tol * _eps : # when |R31| == 1
12101218 # singularity
12111219 rpy [0 ] = 0 # roll is zero
12121220 if R [2 , 0 ] < 0 :
@@ -1229,7 +1237,7 @@ def tr2rpy(
12291237 rpy [1 ] = - math .atan (R [2 , 0 ] * math .cos (rpy [0 ]) / R [2 , 2 ])
12301238
12311239 elif order in ("yxz" , "camera" ):
1232- if abs (abs (R [1 , 2 ]) - 1 ) < 10 * _eps : # when |R23| == 1
1240+ if abs (abs (R [1 , 2 ]) - 1 ) < tol * _eps : # when |R23| == 1
12331241 # singularity
12341242 rpy [0 ] = 0
12351243 if R [1 , 2 ] < 0 :
0 commit comments