贝塞尔曲线的一般表达式(含高阶)
![](https://i-blog.csdnimg.cn/blog_migrate/163b5d6386f59008380c445348d54d97.png)
其中
![](https://i-blog.csdnimg.cn/blog_migrate/d94ff0840ab294fc78e4717807c29ffb.png)
Pi即为给定点的坐标,我们可以分为Px与Py单独计算
import numpy as np
import scipy.special
import matplotlib.pyplot as plt
Px1 = input("")
Px = [int(n) for n in Px1.split()]
Py1 = input("")
Py = [int(n) for n in Py1.split()]
n = len(Px)-1
Coe = []
t = np.linspace(0,1,1000) #步长越长图像越光滑
for i in range(n + 1):
Coe.append(scipy.special.binom(n, i)) #伯恩斯坦多项式系数
def Ber(t,i,n): #伯恩斯坦多项式
B = Coe[i] * (t ** i) * (1 - t) ** (n -i)
return B
def B_x():
Bx=0
for i in range(n+1):
Bx += Px[i]*Ber(t,i,n)
return Bx
def B_y():
By=0
for i in range(n+1):
By += Py[i]*Ber(t,i,n)
return By
plt.plot(Px,Py)
plt.plot(B_x(),B_y())
plt.figure() #绘制Bernstein图像
for i in range(n + 1):
plt.plot(t,Ber(t,i,n))
plt.show()