下面是一个使用
bezier
python包以获取
Bezier curve
.
为了获得“沿该曲线沿x维等距分布”的点,使用
numpy.interp
对于每个坐标
x
需要,相应的曲线坐标
t
是插值的。然后,点的坐标
t型
使用获得
curve.evaluate_multi
再一次。
这个例子是在2D中,但是应该通过定义3D在3D中工作
nodes
%matplotlib inline
import matplotlib.pylab as plt
import bezier
import numpy as np
# Define the Bezier curve
nodes = np.array([
[0.0, 0.2, 1.0, 2.0],
[0.0, 1.8, 0.3, 0.5] ])
curve = bezier.Curve(nodes, degree=3)
t_fine = np.linspace(0, 1, 60) # Curvilinear coordinate
points_fine = curve.evaluate_multi(t_fine)
points_fine.shape # (2, 60)
# Interpolation on regular x coordinates
x_xregular = np.linspace(0, 2, 7)
t_xregular = np.interp(x_xregular, points_fine[0], t_fine)
points_xregular = curve.evaluate_multi(t_xregular)
# Plot
plt.plot(*nodes, '-o', label='definition nodes');
plt.plot(*points_fine, label='Bezier curve');
plt.plot(*points_xregular, 'ok', label='regularly spaced along x');
plt.xlabel('x'); plt.ylabel('y'); plt.legend();