@@ -1296,12 +1296,12 @@ def quat_to_rot(quat):
12961296
12971297
12981298@jit ()
1299- def _one_rot_to_quat (rot ):
1299+ def _one_rot_to_quat (rot , * , tol = 1e-3 ):
13001300 """Convert a rotation matrix to quaternions."""
13011301 # see e.g. http://www.euclideanspace.com/maths/geometry/rotations/
13021302 # conversions/matrixToQuaternion/
13031303 det = np .linalg .det (np .reshape (rot , (3 , 3 )))
1304- if np .abs (det - 1.0 ) > 1e-3 :
1304+ if np .abs (det - 1.0 ) > tol :
13051305 raise ValueError ("Matrix is not a pure rotation, got determinant != 1" )
13061306 t = 1.0 + rot [0 ] + rot [4 ] + rot [8 ]
13071307 if t > np .finfo (rot .dtype ).eps :
@@ -1331,13 +1331,16 @@ def _one_rot_to_quat(rot):
13311331 return np .array ((qx , qy , qz ))
13321332
13331333
1334- def rot_to_quat (rot ):
1334+ def rot_to_quat (rot , * , tol = 1e-3 ):
13351335 """Convert a set of rotations to quaternions.
13361336
13371337 Parameters
13381338 ----------
13391339 rot : array, shape (..., 3, 3)
13401340 The rotation matrices to convert.
1341+ tol : float
1342+ Tolerance for the determinant checking that the rotation matrices are valid.
1343+ The default (1e-3) should be suitable for most cases.
13411344
13421345 Returns
13431346 -------
@@ -1350,7 +1353,7 @@ def rot_to_quat(rot):
13501353 quat_to_rot
13511354 """
13521355 rot = rot .reshape (rot .shape [:- 2 ] + (9 ,))
1353- return np .apply_along_axis (_one_rot_to_quat , - 1 , rot )
1356+ return np .apply_along_axis (_one_rot_to_quat , - 1 , rot , tol = tol )
13541357
13551358
13561359def _quat_to_affine (quat ):
0 commit comments