三次样条插值
根據(jù)起始點以及目標(biāo)點,可以得到若干包含目標(biāo)點的插值曲線,如下圖。
# python代碼import numpy as npimport matplotlib.pyplot as pltx = np.arange(-0.1, 0.2, 0.02)# y = 2(y_start - y_mid) / (x_mid - x_start)^3 * (x - x_start)^3 + 3(y_mid - y_start) / (x_mid - x_start)^2 * (x - x_start)^2 + y_start# x_start=-0.1, y_start=0.8, x_mid=0.1, y_mid=0.9y = -25 * (x + 0.1)**3 + 7.5 * (x + 0.1)**2 + 0.8y2 = 25 * (x + 0.1)**3 - 7.5 * (x + 0.1)**2 + 0.8# x_start=-0.1, y_start=0.8, x_mid=0.1, y_mid=1.0y5 = -50 * (x + 0.1)**3 + 15 * (x + 0.1)**2 + 0.8y6 = 50 * (x + 0.1)**3 - 15 * (x + 0.1)**2 + 0.8# x_start=-0.1, y_start=0.8, x_mid=0.1, y_mid=1.1y7 = -75 * (x + 0.1)**3 + 22.5 * (x + 0.1)**2 + 0.8y8 = 75 * (x + 0.1)**3 - 22.5 * (x + 0.1)**2 + 0.8plt.plot(x, y, 'b-.')plt.plot(x, y2, 'b-.')plt.plot(x, y5, 'b-.')plt.plot(x, y6, 'b-.')plt.plot(x, y7, 'b-.')plt.plot(x, y8, 'b-.')plt.show()''' plt.xlabel("x") plt.ylabel("y") plt.ylim(0, 1) plt.legend() ''' import numpy as npimport matplotlib.pyplot as pltdef cubicSpline(self):fig = plt.figure()sub1 = plt.subplot(1,1,1)plt.xlabel('X(m)')plt.xlim([-0.2, 0.2])plt.ylabel('Y(m)')plt.ylim([0.65,1.05])sub1.spines['top'].set_visible(False)#取消上邊框sub1.spines['right'].set_visible(False) x = np.arange(-0.1, 0.2, 0.02)# y = 2(y_start - y_mid) / (x_mid - x_start)^3 * (x - x_start)^3 + 3(y_mid - y_start) / (x_mid - x_start)^2 * (x - x_start)^2 + y_start# x_start=-0.1, y_start=0.8, x_mid=0.1, y_mid=0.9y = -25 * (x + 0.1)**3 + 7.5 * (x + 0.1)**2 + 0.8y2 = 25 * (x + 0.1)**3 - 7.5 * (x + 0.1)**2 + 0.8# rotate 45°xs, ys = x[0], y[0]an = 45*np.pi/180x3 = (x - xs) * np.cos(an) - (y - ys) * np.sin(an) + xsy3 = (x - xs) * np.sin(an) + (y - ys) * np.cos(an) + ys x4 = (x - xs) * np.cos(an) - (y2 - ys) * np.sin(an) + xsy4 = (x - xs) * np.sin(an) + (y2 - ys) * np.cos(an) + ysplt.plot(x, y, 'b-.')plt.plot(x, y2, 'b-.')plt.plot(x3, y3, 'r-.')plt.plot(x4, y4, 'r-.')plt.show()總結(jié)
- 上一篇: 路径规划后对路径进行平滑处理
- 下一篇: UR驱动包安装过程及遇到问题的解决方案