2015-10-20 129 views

回答

2

您是否确定需要NURBS曲面?据我所知, 它们比b样条表面的主要优点是它们可以精确地模拟圆弧。我已经使用了多年的翼型,弧线不是 对我来说特别有用。

反正romeric是正确的,他说有什么类似于scipy.interpolate.splprep的表面。 但如果你不反对滚动您自己,您可以从形状(3,M,N),其中“M”为每节点数的你部分的数据创建一个三维阵列 ,“N”是 部分的数量,第一个维度保存mxn网格上的x,y和z值。 一旦你有,你可以使用scipy.interpolate.RectBivariateSpline来为X,Y和Z坐标 3个独立的2D参数曲面。然后编写一个类 一个类,将它们组合到3D空间中的单个2D表面中,以便当您调用 mysurf.ev(0.5, 0.2)时,它会评估嵌入在类中的实例并返回(x,y,z)坐标。

我已经发布了一个要求here,可能会让你开始。要尝试它,请从命令行运行它,或者执行此操作:

from bsplinesurf import DemoBSplineSurf 
srf = DemoBSplineSurf() 
srf.plot() 
4

您可以使用scipy.interpolate

import numpy as np 
import matplotlib.pyplot as plt 
from scipy.interpolate import splev, splrep 

x = np.linspace(0, 10, 10) # x-coordinates 
y = np.sin(x) # y-coordinates 
tck = splrep(x, y) # get bspline representation given (x,y) values 
x2 = np.linspace(0, 10, 200) # new set of values, just to check 
y2 = splev(x2, tck) # evaluate the y values of new coordinates on NURBS curve 
plt.plot(x, y, 'o', x2, y2) 
plt.show() 

enter image description here

元组tck包含您的节点矢量和控制点(系数)。在SciPy中还涉及更多的例程,请看here

请注意,这些仅适用于bspline曲线。据我所知,在SciPy中没有表面的等价方法。如果您想使用表面,根据您的需求,您可以使用igakit

from igakit.cad import ruled, circle 
c1 = circle(angle=(0,np.pi/2.)) 
c2 = circle(radius=2,angle=(0,np.pi/2.)) 
print "knot vector:", c1.knots 
print "control points:", c1.control 
srf = ruled(c1,c2) 
plt.plot(srf) 
plt.show() 

knot vector: (array([ 0., 0., 0., 1., 1., 1.]),) 
control points: array([[ 1.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00], 
    [ 7.07106781e-01, 7.07106781e-01, 0.00000000e+00, 7.07106781e-01], 
    [ 2.22044605e-16, 1.00000000e+00, 0.00000000e+00, 1.00000000e+00]]) 

enter image description here

NURBS package。对于爱好者来说,BlenderSalome具有完整的Python API,适用于所有NURBS曲线/曲面族,后者基于OpenCascade