简体   繁体   English

如何在没有任何方程的情况下计算python中不规则物体的体积?

[英]how to calculate volume of irregular object in python without the any equation?

I have a model formed by Contour lines in X,Y coordinates and forms an irregular model with constant height of 3 in Z axis?我有一个由 X、Y 坐标中的轮廓线形成的模型,并在 Z 轴上形成一个高度为 3 的不规则模型? I would like to find the volume of this model in python probably using Scipy module I have points of all the contour slices我想在 python 中找到这个模型的体积,可能使用 Scipy 模块我有所有轮廓切片的点

The image as shown below如下图所示

在此处输入图片说明

You can use the convex hull method for calculating the volume of any solid formed by a cloud of points.您可以使用凸包方法计算由点云形成的任何实体的体积。

Scipy has a class for calculating the ConvexHull . Scipy 有一个用于计算ConvexHull的类。

According to Eaton (2013), "a convex hull is defined as the smallest convex set containing all of the points from a point cloud. The volume is formed from triplets of points and thus creates a tessellated convex volume comprised of triangular surface elements. Informally, a convex hull can be viewed as a shrink-wrapped surface around the exterior of the point cloud. The method characteristics are 1) the hull is unique for a given point cloud, and 2) it is a conservative estimate of the volume, since it is the smallest convex volume that contains the points" (p.307).根据伊顿 (2013) 的说法,“凸包被定义为包含点云中所有点的最小凸集。体积由点的三元组形成,从而创建由三角形表面元素组成的镶嵌凸体积。非正式地, 凸包可以看作是围绕点云外部的收缩包裹表面. 该方法的特点是 1) 包对于给定的点云是唯一的, 和 2) 它是体积的保守估计, 因为它是包含点的最小凸体积”(第 307 页)。

To calculate the volume of your solid, you have to create a numpy array with dimentions [n_samples,3], calculate the hull using the scipy class, then check the hull volume attribute.要计算实体的体积,您必须创建一个具有维度 [n_samples,3] 的 numpy 数组,使用 scipy 类计算船体,然后检查船体体积属性。 Example:例子:

import numpy as np
from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# Using spherical coordinates to generate points on the surface
def sphere_points(samples,radius=1):
    # Random samples in the ranges 0<=theta<=2pi, 0<=phi<=pi
    theta = 2*np.pi*np.random.rand(samples,)
    phi  = np.pi*np.random.rand(samples,)

    # Making retangular coordinates from the spherical coordinates
    x=radius*np.cos(theta)*np.sin(phi)
    y=radius*np.sin(theta)*np.sin(phi)
    z=radius*np.cos(phi)

    return(np.transpose(np.array([x,y,z])))

# Calculating N=10000 points in a spherical surface 
sph_array=sphere_points(10000)

# Calculate the Hull
hull = ConvexHull(sph_array)

# Once the hull is calculated, you can consult the volume attribute
hull.volume

Following is an example to calculate the volume of a sphere using different number of points.以下是使用不同点数计算球体体积的示例。 As described before, the calculation is always conservative, meaning the volume will converge from below the exact answer (4/3)PiR^3:如前所述,计算始终是保守的,这意味着交易量将从准确答案 (4/3)PiR^3 以下收敛:

samples=[10,25,50,75,100,250,500,750,1000,2500,5000,7500,10000]
volume=[]

for sample in samples:
    sph_array=sphere_points(sample)
    hull = ConvexHull(sph_array)
    volume.append(hull.volume)

fig = plt.figure(figsize=(6,6))
ax = fig.add_subplot(111)
ax.scatter(samples,volume,label=('ConvexHull volume'))
ax.set_xscale('log')
ax.axhline(y=(4/3)*np.pi,c='r',label=('Sphere volume (4/3)Pi R^3'))
ax.set_xlabel('Samples')
ax.set_ylabel('Volume (m^3)')
ax.set_title('Convergence of sphere volume')
ax.legend(loc='lower right')
plt.show()

球体体积的收敛

References:参考:

Barber et al., 1993 .巴伯等人,1993 年

Eaton, Maulianda, et al.伊顿、毛利安达等。 (2013). (2013)。 “Estimation of stimulated reservoir volume (SRV) using microseismic observations”. “使用微地震观测估计受激储层体积 (SRV)”。 In: MIC - Annual Research Report.在:MIC - 年度研究报告。 Vol.卷。 3. Calgary AB. 3. 卡尔加里 AB。

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

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