本文介绍了如何使用scipy.integrate来获得截断的球体的体积?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力使用scipy.integrate,我使用过tplquad,但是如何使用integrate来获取(截断的)球体的体积?谢谢

I'm struggling with using scipy.integrate, I used tplquad, but how can I used integrate to get the volume of (truncated)sphere? Thanks

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

推荐答案

要按角度截断,使用球形坐标系很方便.假设从取自阿肯色州TU radius (r)theta (t)phi (p)为:

To truncate by angle it is convenient to use a spherical coordinate systems. Assuming the definition taken from Arkansas TU for radius (r), theta (t) and phi (p) as :

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

Then, you can truncate setting the limits: 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 ).在这里,我将截去一半的球以进行演示:

To truncate by plane it is convenient to use a cartesian coordinate system (x,y,z), where x**2+y**2+z**2=R**2 (see mathworld). Here I am truncating half of the sphere to demonstrate:

from `x1=-R` to `x2=R`<br>
from `y1=0` to `y2=(R**2-x**2)**0.5`<br>
from `z1=-(R**2-x**2-y**2)**0.5` to `z2=(R**2-x**2-y**2)**0.5`<br>
(an useful example using lambdas):

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]

这篇关于如何使用scipy.integrate来获得截断的球体的体积?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 15:44