簡體   English   中英

如何使用 scipy.integrate 獲取截斷球體的體積?

[英]how to use scipy.integrate to get the volume of a truncated sphere?

我正在努力使用 scipy.integrate,我使用了 tplquad,但是我如何使用integrate來獲得(截斷的)球體的體積? 謝謝

import scipy
from scipy.integrate import quad, dblquad, tplquad
from math import*
from numpy import *

R = 0.025235 #radius
theta0 = acos(0.023895) #the angle from the edge of truncated plane to the center of
sphere

def f_1(phi,theta,r):
    return r**2*sin(theta)*phi**0
Volume = tplquad(f_1, 0.0,R, lambda y: theta0, lambda y: pi, lambda y,z: 0.0,lambda
y,z: 2*pi)

print Volume

要按角度截斷,使用球坐標系很方便。 假設取自阿肯色州 TUradius (r)theta (t)phi (p)為:球坐標圖

然后,您可以截斷設置限制: r1 r2 t1 t2 p1 p2

import scipy
from scipy.integrate import quad, dblquad, tplquad
from numpy import *

# limits for radius
r1 = 0.
r2 = 1.

# limits for theta
t1 = 0
t2 = 2*pi

# limits for phi
p1 = 0
p2 = pi

def diff_volume(p,t,r):
    return r**2*sin(p)

volume = tplquad(diff_volume, r1, r2, lambda r:   t1, lambda r:   t2,
                                      lambda r,t: p1, lambda r,t: p2)[0]

要按平面截斷,可以方便地使用笛卡爾坐標系(x,y,z) ,其中x**2+y**2+z**2=R**2參見 mathworld )。 在這里,我截斷球體的一半來演示:

  • x1=-Rx2=R
  • y1=0y2=(R**2-x**2)**0.5
  • z1=-(R**2-x**2-y**2)**0.5z2=(R**2-x**2-y**2)**0.5

使用 lambda 的一個有用示例:

R= 2.

# limits for x
x1 = -R
x2 = R

def diff_volume(z,y,x):
    return 1.

volume = tplquad(diff_volume, x1, x2,
                 lambda x: 0., lambda x: (R**2-x**2)**0.5,
                 lambda x,y: -(R**2-x**2-y**2)**0.5,
                 lambda x,y:  (R**2-x**2-y**2)**0.5 )[0]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM