scipy.spatial.transform.
RotationSpline#
- class scipy.spatial.transform.RotationSpline(times, rotations)[原始碼]#
以連續角速率和加速度內插旋轉。
每個連續方向之間的旋轉向量是時間的三次函數,並且保證角速率和加速度是連續的。這種內插法類似於三次樣條內插法。
有關數學和實作細節,請參閱 [1]。
- 參數:
- timesarray_like,形狀 (N,)
已知旋轉的時間。必須指定至少 2 個時間。
- rotations
Rotation
實例 用於執行內插的旋轉。必須包含 N 個旋轉。
參考文獻
範例
>>> from scipy.spatial.transform import Rotation, RotationSpline >>> import numpy as np
從尤拉角定義時間和旋轉序列
>>> 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)
內插尤拉角、角速率和加速度
>>> 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()
角速率也是平滑的
>>> plt.plot(times_plot, angular_rate_plot) >>> plt.plot(times, angular_rate, 'x') >>> plt.title("Angular rate") >>> plt.show()
角加速度是連續的,但不平滑。另請注意,角加速度不是分段線性函數,因為它與旋轉向量的二階導數(在三次樣條中是分段線性函數)不同。
>>> plt.plot(times_plot, angular_acceleration_plot) >>> plt.plot(times, angular_acceleration, 'x') >>> plt.title("Angular acceleration") >>> plt.show()
方法
__call__
(times[, order])計算內插值。