使用 R 语言(积分)使用 3 个平面切割球体的一部分的体积
Volume of a part of a sphere cutted using 3 planes using R-Language (integral)
我想计算一部分球体的体积(V),它是球体与三个palnes相交的结果(x= 0, y=0 和 z=1.5)。我正在使用 R-Language,这是我的代码。我使用笛卡尔坐标和极坐标尝试了 2 种不同的方法。他们都给出了否定的答案。
## Compute the Volume between 3 planes x=0, y=0 and z=1.5 and a sphere
library("pracma", lib.loc="~/R/win-library/3.1")
f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1.5 ) # here the function(x,y) is subtracted with -1.5 which represents the plane z=1.5
xmin <- 0
xmax <- 2
ymin <- 0
ymax <- function(x) (sqrt(4 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q # Integral over sector is not so exact
# Exact Volume from AutoCAD V=0.3600
## Volume of the sphere: use polar coordinates
f0 <- function(x, y) (sqrt(4 - x^2 - y^2)-1.5) # for x^2 + y^2 <= 4 the f(x,y) means z changes between zmin=1 and zmax= sqrt(4-x^2-y^2)
fp <- function(t, r) r * f0(r*cos(t), r*sin(t))
quad2d(fp, 0, pi/2, 0, 2, n = 101) # -0.523597
正确答案是 V= 0.3600 。任何人都可以给我提示吗?
干杯
您的 X-Y 积分区域涵盖 f(x,y)-1.5
为负和正的区域。你的球体与直线 z=1.5
的交点是一个半径为 sqrt(7/4)
的圆(使用毕达哥拉斯),因此适当调整你的极限,你会得到:
library(pracma)
f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1.5 ) # here the function(x,y) is subtracted with -1.5 which represents the plane z=1.5
xmin <- 0
xmax <- sqrt(7/4)
ymin <- 0
ymax <- function(x) (sqrt(7/4 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q # Integral over sector is not so exact
# [1] 0.3599741
非常接近您的预期。
我已经解决了 r=2 的球体和球体 shell 与 3 个平面 x=1、y=1 和 z=1 之间的交集体积。
## Compute the Volume between 3 planes x=1.0, y=1.0 and z=1.0 and a sphere
library(pracma)
f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1 ) # here the function(x,y) is subtracted with -1.5 which represents the plane z=1.5
xmin <- 1
xmax <- sqrt(2)
ymin <- 1
ymax <- function(x) (sqrt(3 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q #
# [1] 0.01520549
# Exact Volume from AutoCAD: 0.0152
我想计算一部分球体的体积(V),它是球体与三个palnes相交的结果(x= 0, y=0 和 z=1.5)。我正在使用 R-Language,这是我的代码。我使用笛卡尔坐标和极坐标尝试了 2 种不同的方法。他们都给出了否定的答案。
## Compute the Volume between 3 planes x=0, y=0 and z=1.5 and a sphere
library("pracma", lib.loc="~/R/win-library/3.1")
f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1.5 ) # here the function(x,y) is subtracted with -1.5 which represents the plane z=1.5
xmin <- 0
xmax <- 2
ymin <- 0
ymax <- function(x) (sqrt(4 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q # Integral over sector is not so exact
# Exact Volume from AutoCAD V=0.3600
## Volume of the sphere: use polar coordinates
f0 <- function(x, y) (sqrt(4 - x^2 - y^2)-1.5) # for x^2 + y^2 <= 4 the f(x,y) means z changes between zmin=1 and zmax= sqrt(4-x^2-y^2)
fp <- function(t, r) r * f0(r*cos(t), r*sin(t))
quad2d(fp, 0, pi/2, 0, 2, n = 101) # -0.523597
正确答案是 V= 0.3600 。任何人都可以给我提示吗?
干杯
您的 X-Y 积分区域涵盖 f(x,y)-1.5
为负和正的区域。你的球体与直线 z=1.5
的交点是一个半径为 sqrt(7/4)
的圆(使用毕达哥拉斯),因此适当调整你的极限,你会得到:
library(pracma)
f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1.5 ) # here the function(x,y) is subtracted with -1.5 which represents the plane z=1.5
xmin <- 0
xmax <- sqrt(7/4)
ymin <- 0
ymax <- function(x) (sqrt(7/4 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q # Integral over sector is not so exact
# [1] 0.3599741
非常接近您的预期。
我已经解决了 r=2 的球体和球体 shell 与 3 个平面 x=1、y=1 和 z=1 之间的交集体积。
## Compute the Volume between 3 planes x=1.0, y=1.0 and z=1.0 and a sphere
library(pracma)
f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1 ) # here the function(x,y) is subtracted with -1.5 which represents the plane z=1.5
xmin <- 1
xmax <- sqrt(2)
ymin <- 1
ymax <- function(x) (sqrt(3 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q #
# [1] 0.01520549
# Exact Volume from AutoCAD: 0.0152