如何在 SciPy 中沿着 3D 样条曲线找到点?
How to find points along a 3D spline curve in SciPy?
我想做这样的曲线:
一条3D曲线,在space中有3个点定义了曲线穿过的终点和中点,但在space中还有2个点使曲线弯曲朝着 不碰。
类似于在 Inkscape 中使用二维点定义曲线:
此外,我想沿 space 的 x 维度平均计算这条曲线上的点 spaced。 (沿定义样条的 t 变量不等 spaced,沿曲线长度不等 spaced。曲线不会沿 x 维度回溯。)
我试过阅读 the documentation,但我很困惑。它要么显示通过所有点的曲线:
或 none 个:
这是使用 bezier
python package to obtain points along a Bezier curve 的代码。
要获得点 "along this curve equally spaced along the x dimension",使用 numpy.interp
执行线性插值。
对于每个想要的坐标 x
,对应的曲线坐标 t
被插值。然后,再次使用curve.evaluate_multi
获得t
点的坐标。
该示例是 2D 的,但应该通过定义 3D nodes
坐标在 3D 中工作。
%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();
我想做这样的曲线:
一条3D曲线,在space中有3个点定义了曲线穿过的终点和中点,但在space中还有2个点使曲线弯曲朝着 不碰。
类似于在 Inkscape 中使用二维点定义曲线:
此外,我想沿 space 的 x 维度平均计算这条曲线上的点 spaced。 (沿定义样条的 t 变量不等 spaced,沿曲线长度不等 spaced。曲线不会沿 x 维度回溯。)
我试过阅读 the documentation,但我很困惑。它要么显示通过所有点的曲线:
或 none 个:
这是使用 bezier
python package to obtain points along a Bezier curve 的代码。
要获得点 "along this curve equally spaced along the x dimension",使用 numpy.interp
执行线性插值。
对于每个想要的坐标 x
,对应的曲线坐标 t
被插值。然后,再次使用curve.evaluate_multi
获得t
点的坐标。
该示例是 2D 的,但应该通过定义 3D nodes
坐标在 3D 中工作。
%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();