繁体   English   中英

如何在SciPy中沿着3D样条曲线找到点?

[英]How to find points along a 3D spline curve in SciPy?

我想画一条曲线:

3D曲线

3D曲线,在空间中有3个点定义了曲线的终点和中间点,在空间中还有2个点,曲线向该点弯曲没有接触。

类似于在Inkscape中使用2D点定义曲线:

在此处输入图片说明

另外,我想计算沿着这条曲线沿点的x维度等距分布的点。 (沿定义样条曲线的t变量不等距,并且沿曲线长度不等距。曲线不会沿x维度回退。)

我尝试阅读文档 ,但感到困惑。 它要么显示通过所有点的曲线:

在此处输入图片说明

或没有一个:

在此处输入图片说明

这是一个使用bezier python包获取沿Bezier曲线的点的代码。

为了获得“沿x方向等间距分布的曲线”点,使用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();

示例图

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM