|
16 | 16 | # pylint: disable=invalid-name |
17 | 17 | from __future__ import annotations |
18 | 18 | import math |
| 19 | +import warnings |
19 | 20 | import numpy as np |
20 | 21 | from typing import Any |
21 | 22 | import spatialmath.base as smb |
@@ -2073,7 +2074,7 @@ def interp1(self, s: float = 0, shortest: Optional[bool] = False) -> UnitQuatern |
2073 | 2074 | """ |
2074 | 2075 | Interpolate a unit quaternion |
2075 | 2076 |
|
2076 | | - :param shortest: Take the shortest path along the great circle |
| 2077 | + :param shortest: deprecated, has no effect |
2077 | 2078 | :param s: interpolation coefficient, range 0 to 1, or number of steps |
2078 | 2079 | :type s: array_like or int |
2079 | 2080 | :return: interpolated unit quaternion |
@@ -2104,19 +2105,39 @@ def interp1(self, s: float = 0, shortest: Optional[bool] = False) -> UnitQuatern |
2104 | 2105 |
|
2105 | 2106 | .. note:: values of ``s`` are silently clipped to the range [0, 1] |
2106 | 2107 |
|
| 2108 | + .. note:: ``shortest`` can never change the result here. Every |
| 2109 | + ``UnitQuaternion`` has a non-negative scalar part by construction |
| 2110 | + (see :func:`~spatialmath.base.quaternions.qunit`), and this method |
| 2111 | + always interpolates *from* the identity quaternion ``[1,0,0,0]`` |
| 2112 | + -- whose dot product with any unit quaternion is just that |
| 2113 | + quaternion's own (always non-negative) scalar part. A negative |
| 2114 | + dot product is what ``shortest`` checks for to detect "the long |
| 2115 | + way round", and that condition can never occur here, unlike |
| 2116 | + :meth:`interp`, where it can. |
| 2117 | +
|
| 2118 | + .. deprecated:: 1.1.19 |
| 2119 | + ``shortest`` has no effect and will be removed in a future |
| 2120 | + release. |
| 2121 | +
|
2107 | 2122 | :seealso: :func:`~spatialmath.base.quaternions.qslerp` |
2108 | 2123 | """ |
2109 | 2124 | # TODO allow self to have len() > 1 |
2110 | 2125 |
|
| 2126 | + if shortest: |
| 2127 | + warnings.warn( |
| 2128 | + "shortest has no effect on interp1 and will be removed in a " |
| 2129 | + "future release: interpolation from the identity quaternion " |
| 2130 | + "is always the shortest path", |
| 2131 | + DeprecationWarning, |
| 2132 | + ) |
| 2133 | + |
2111 | 2134 | if isinstance(s, int) and s > 1: |
2112 | 2135 | s = np.linspace(0, 1, s) |
2113 | 2136 | else: |
2114 | 2137 | s = smb.getvector(s) |
2115 | 2138 | s = np.clip(s, 0, 1) # enforce valid values |
2116 | 2139 |
|
2117 | | - q0_endpoint, q0, q1, sin_theta, theta = _qslerp_prepare( |
2118 | | - smb.qeye(), self.vec, shortest=shortest |
2119 | | - ) |
| 2140 | + q0_endpoint, q0, q1, sin_theta, theta = _qslerp_prepare(smb.qeye(), self.vec) |
2120 | 2141 | qi = [] |
2121 | 2142 | for sk in s: |
2122 | 2143 | if sk == 0: |
|
0 commit comments