python如何画贝塞尔曲线_python bezier 曲线

defpoint_bezier(avoid_point):globalp

xs= avoid_point[0, 0] #0

ys = avoid_point[1, 0] #0

xe = avoid_point[0, -1] #34.5844

ye = avoid_point[1, -1] #0

Latoff = 2.3startp=np.array([xs, ys])

endp=np.array([xe, ye])

endp1= np.array([xe+2, ye])#print(startp, endp)

P0 =startp

P1= np.array([startp[0] + (endp[0] - startp[0]) / 8, startp[1]])

P2= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 2, startp[1]])

P3= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 2, startp[1] +Latoff])

P4= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 3, startp[1] +Latoff])

P5= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 4, startp[1] +Latoff])

P6= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 5, startp[1] +Latoff])

P7= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 6, startp[1] +Latoff])

P8= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 6, startp[1] +Latoff])

P9= np.array([startp[0] + (endp[0] - startp[0]) / 8 * 7, startp[1]])

P10=endp

P11=endp1

i= 1half_length= 0.5 * (xe +xs)for u in np.arange(startp[0], startp[0] + (endp[0] - startp[0]) / 2, 0.2):#for u =startp[0]:0.2: startp[1] + (endp[1] - startp[1]) / 2

c = (1 - (u - startp[0]) / half_length) ** 5 * P0 + 5 * (1 - (u - startp[0]) / half_length) ** 4 *(

u- startp[0]) / half_length * P1 + 10 * (1 - (u - startp[0]) / half_length) ** 3 *(

(u- startp[0]) / half_length) ** 2 * P2 + 10 * (1 - (u - startp[0]) / half_length) ** 2 *(

(u- startp[0]) / half_length) ** 3 * P3 + 5 * (1 - (u - startp[0]) / half_length) *(

(u- startp[0]) / half_length) ** 4 * P4 + ((u - startp[0]) / half_length) ** 5 *P5

i= i + 1p= np.append(p, [c], axis=0)for u in np.arange(startp[0] + half_length, endp[0], 0.2):

d= (1 - (u - startp[0] - half_length) / half_length) ** 5 * P6 + 5 *(1 - (u - startp[0] - half_length) / half_length) ** 4 *(

u- startp[0] - half_length) / half_length * P7 + 10 *(1 - (u - startp[0] - half_length) / half_length) ** 3 *(

(u- startp[0] - half_length) / half_length) ** 2 * P8 + 10 *(1 - (u - startp[0] - half_length) / half_length) ** 2 *(

(u- startp[0] - half_length) / half_length) ** 3 * P9 + 5 *(1 - (u - startp[0] - half_length) / half_length) *(

(u- startp[0] - half_length) / half_length) ** 4 * P10 +(

(u- startp[0] - half_length) / half_length) ** 5 *P11

i= i + 1p= np.append(p, [d], axis=0)returnp#print(p)

#plt.plot(p[:, 0], p[:, 1], 'r')

#plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值