Compute the angle and distance between two rigid transforms. Parameters ---------- a : array, shape (..., 4, 4) First rigid transform. b : array, shape (..., 4, 4) | None Second rigid transform. If None, the identity transform is used. angle_units : str U
(a, b=None, *, angle_units="rad", distance_units="m")
| 1372 | |
| 1373 | |
| 1374 | def angle_distance_between_rigid(a, b=None, *, angle_units="rad", distance_units="m"): |
| 1375 | """Compute the angle and distance between two rigid transforms. |
| 1376 | |
| 1377 | Parameters |
| 1378 | ---------- |
| 1379 | a : array, shape (..., 4, 4) |
| 1380 | First rigid transform. |
| 1381 | b : array, shape (..., 4, 4) | None |
| 1382 | Second rigid transform. If None, the identity transform is used. |
| 1383 | angle_units : str |
| 1384 | Units for the angle output, either "rad" or "deg". |
| 1385 | distance_units : str |
| 1386 | Units for the distance output, either "m" or "mm". |
| 1387 | |
| 1388 | Returns |
| 1389 | ------- |
| 1390 | angles : array, shape (...) |
| 1391 | The angles between the two transforms. |
| 1392 | distances : array, shape (...) |
| 1393 | The distances between the two transforms. |
| 1394 | |
| 1395 | Notes |
| 1396 | ----- |
| 1397 | .. versionadded:: 1.11 |
| 1398 | """ |
| 1399 | a = _affine_to_quat(a, name="a") |
| 1400 | b = np.zeros(6) if b is None else _affine_to_quat(b, name="b") |
| 1401 | ang = _angle_between_quats(a[..., :3], b[..., :3]) |
| 1402 | dist = np.linalg.norm(a[..., 3:] - b[..., 3:], axis=-1) |
| 1403 | assert isinstance(angle_units, str) and angle_units in ("rad", "deg") |
| 1404 | if angle_units == "deg": |
| 1405 | ang = np.rad2deg(ang) |
| 1406 | assert isinstance(distance_units, str) and distance_units in ("m", "mm") |
| 1407 | if distance_units == "mm": |
| 1408 | dist *= 1e3 |
| 1409 | return ang, dist |
| 1410 | |
| 1411 | |
| 1412 | def _angle_between_quats(x, y=None): |