if (interactive()) {
# Example 1: Spherical shell: a <= r <= b, independent of angles
R1 <- function(th, ph) 0.8
R2 <- function(th, ph) 1.2
out <- solid_spherical3d(
R1, R2,
theta_range = c(0, 2*pi),
phi_range = c(0, pi),
plot = TRUE,
colorscales = list("Blues", "Reds"),
opacities = c(0.25, 0.35),
compute_volume = TRUE
)
out$volume$estimate # approximately 4/3 * pi * (1.2^3 - 0.8^3)
# Example 2: Spherical cap: 0 <= r <= 1, phi in [0, pi/3]
R1 <- function(th, ph) 0
R2 <- function(th, ph) 1
out2 <- solid_spherical3d(
R1, R2,
theta_range = c(0, 2*pi),
phi_range = c(0, pi/3),
plot = TRUE,
compute_volume = TRUE
)
out2$volume$estimate # analytic value matches the standard spherical cap formula
}
Run the code above in your browser using DataLab