scipy.spatial.transform.RotationSpline

class scipy.spatial.transform.RotationSpline(times, rotations)[源代码]

使用连续的角速率和加速度插值旋转。

每个连续方向之间的旋转矢量是时间的三次函数,并且保证角速度和加速度是连续的。这种插值类似于三次样条插值。

请参阅 [1] 了解数学和实现细节。

参数
times类似阵列,形状(N,)

已知旋转的次数。必须至少指定2次。

旋转Rotation 实例循环实例

旋转以执行其间的插值。必须包含N个旋转。

参考文献

1

Smooth Attitude Interpolation

示例

>>> from scipy.spatial.transform import Rotation, RotationSpline

从欧拉角度定义时间和旋转的顺序:

>>> times = [0, 10, 20, 40]
>>> angles = [[-10, 20, 30], [0, 15, 40], [-30, 45, 30], [20, 45, 90]]
>>> rotations = Rotation.from_euler('XYZ', angles, degrees=True)

创建插值器对象:

>>> spline = RotationSpline(times, rotations)

插值Euler角度、角速率和加速度:

>>> angular_rate = np.rad2deg(spline(times, 1))
>>> angular_acceleration = np.rad2deg(spline(times, 2))
>>> times_plot = np.linspace(times[0], times[-1], 100)
>>> angles_plot = spline(times_plot).as_euler('XYZ', degrees=True)
>>> angular_rate_plot = np.rad2deg(spline(times_plot, 1))
>>> angular_acceleration_plot = np.rad2deg(spline(times_plot, 2))

在此图中,您可以看到欧拉角是连续且平滑的:

>>> import matplotlib.pyplot as plt
>>> plt.plot(times_plot, angles_plot)
>>> plt.plot(times, angles, 'x')
>>> plt.title("Euler angles")
>>> plt.show()
../../_images/scipy-spatial-transform-RotationSpline-1_00_00.png

角速率也很平滑:

>>> plt.plot(times_plot, angular_rate_plot)
>>> plt.plot(times, angular_rate, 'x')
>>> plt.title("Angular rate")
>>> plt.show()
../../_images/scipy-spatial-transform-RotationSpline-1_01_00.png

角加速度是连续的,但不是平滑的。还要注意,角加速度不是分段线性函数,因为它不同于旋转向量的二阶导数(与三次样条一样是分段线性函数)。

>>> plt.plot(times_plot, angular_acceleration_plot)
>>> plt.plot(times, angular_acceleration, 'x')
>>> plt.title("Angular acceleration")
>>> plt.show()
../../_images/scipy-spatial-transform-RotationSpline-1_02_00.png

方法:

__call__ \(次数[, order] )

计算插值值。