|
39 | 39 |
|
40 | 40 | _eps = np.finfo(np.float64).eps |
41 | 41 |
|
42 | | -try: # pragma: no cover |
43 | | - # print('Using SymPy') |
44 | | - import sympy |
45 | | - |
46 | | - _symbolics = True |
47 | | - |
48 | | -except ImportError: # pragma: no cover |
49 | | - _symbolics = False |
50 | | - |
51 | 42 |
|
52 | 43 | # ---------------------------------------------------------------------------------------# |
53 | 44 | def rot2(theta: float, unit: str = "rad") -> SO2Array: |
@@ -170,8 +161,13 @@ def tr2xyt(T: SE2Array, unit: str = "rad") -> R3: |
170 | 161 | :seealso: trot2 |
171 | 162 | """ |
172 | 163 |
|
173 | | - if T.dtype == "O" and _symbolics: |
174 | | - angle = sympy.atan2(T[1, 0], T[0, 0]) |
| 164 | + if T.dtype == "O": |
| 165 | + try: |
| 166 | + import sympy |
| 167 | + except ImportError: |
| 168 | + angle = math.atan2(T[1, 0], T[0, 0]) |
| 169 | + else: |
| 170 | + angle = sympy.atan2(T[1, 0], T[0, 0]) |
175 | 171 | else: |
176 | 172 | angle = math.atan2(T[1, 0], T[0, 0]) |
177 | 173 | return np.r_[T[0, 2], T[1, 2], angle] |
@@ -367,7 +363,12 @@ def ishom2(T: Any, check: bool = False, tol: float = 20) -> bool: # TypeGuard(S |
367 | 363 | and T.shape == (3, 3) |
368 | 364 | and ( |
369 | 365 | not check |
370 | | - or (smb.isR(T[:2, :2], tol=tol) and all(T[2, :] == np.array([0, 0, 1]))) |
| 366 | + or ( |
| 367 | + smb.isR(T[:2, :2], tol=tol) |
| 368 | + and T[2, 0] == 0 |
| 369 | + and T[2, 1] == 0 |
| 370 | + and T[2, 2] == 1 |
| 371 | + ) |
371 | 372 | ) |
372 | 373 | ) |
373 | 374 |
|
@@ -1312,7 +1313,11 @@ def _FindCorrespondences( |
1312 | 1313 |
|
1313 | 1314 | num_iter += 1 |
1314 | 1315 |
|
1315 | | - return T |
| 1316 | + # T accumulates roundoff error through repeated composition |
| 1317 | + # (T = T @ new_T) over the iterations above, and can drift just |
| 1318 | + # outside ishom2()'s orthonormality tolerance -- restore exact |
| 1319 | + # orthonormality before returning. |
| 1320 | + return trnorm2(T) |
1316 | 1321 |
|
1317 | 1322 |
|
1318 | 1323 | if _matplotlib_exists: |
|
0 commit comments