如果要严格遵守梯形法则,可以执行以下 *** 作:
import numpy as npimport scipy.spatialdef main(): xyz = np.random.random((100, 3)) area_underneath = trapezoidal_area(xyz) print area_underneathdef trapezoidal_area(xyz): """Calculate volume under a surface defined by irregularly spaced points using delaunay triangulation. "x,y,z" is a <numpoints x 3> shaped ndarray.""" d = scipy.spatial.Delaunay(xyz[:,:2]) tri = xyz[d.vertices] a = tri[:,0,:2] - tri[:,1,:2] b = tri[:,0,:2] - tri[:,2,:2] proj_area = np.cross(a, b).sum(axis=-1) zavg = tri[:,:,2].sum(axis=1) vol = zavg * np.abs(proj_area) / 6.0 return vol.sum()main()
样条曲线或线性(梯形)插值是否更合适,在很大程度上取决于您的问题。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)