查找不规则数据点定义的体积-python [英] Find volume defined by irregular data points - python

查看:223
本文介绍了查找不规则数据点定义的体积-python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python查找给定一组数据点(x,y,z)的体积.这些数据点是从实验中收集的样本(因此绘制的表面可能非常不规则).我已经解决了如何创建3D图,但没有解决如何使用python计算体积的问题.

I am trying to find the volume given a set of data points (x,y,z) using python. These data points are samples collected from an experiment (so the plotted surface can be quite irregular). I have worked out how to create a 3D plot but not how to calculate the volume using python.

X, Y = np.meshgrid(x, y)
Z = griddata(xpts, ypts, zpts, x, y)
fig = plt.figure()
ax = fig.gca(projection='3d')               
surf = ax.plot_surface(X, Y, Z,           
                       rstride=5,           
                       cstride=5,           
                       cmap=cm.jet,         
                       linewidth=0,         
                       antialiased=True,
                       vmin=np.nanmin(Z),
                       vmax = np.nanmax(Z))

这是使用python查找不规则表面下的区域的类似问题,.可以调整它来查找音量吗? 任何帮助表示赞赏. 谢谢.

Here's a similar question to find the area under an irregular surface using python, Volume under "plane" defined by data points - python. Could this be adapted to find the volume? Any help is appreciated. Thanks.

推荐答案

我会很懒,像黑盒子一样使用ConvexHull:

I would be lazy and use ConvexHull like a black box:

import scipy.spatial as ss
import numpy as np
npoints = 6
ndimensions = 3
points = np.random.rand(npoints, ndimensions)
hull = ss.ConvexHull(points)
print('volume inside points is: ',hull.volume)

尽管这可能不是CPU优化的,因为ConvexHull计算了很多东西.

though this is probably not CPU-optimized since ConvexHull computes a bunch of things.

希望这会有所帮助.

这篇关于查找不规则数据点定义的体积-python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆