#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a sphere of radius 10
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
coords <- gen_isosurface(
f = function(x, y, z) {x^2 + y^2 + z^2},
upper = 10^2
)
coords |>
isocubesGrob() |>
grid::grid.draw()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a complex shape
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grid::grid.newpage()
f <- function(x, y, z) {
(x-2)^2 * (x+2)^2 +
(y-2)^2 * (y+2)^2 +
(z-2)^2 * (z+2)^2 +
3 * (x^2 * y^2 + x^2 * z^2 + y^2 * z^2) +
6 * x * y * z -
10 * (x^2 + y^2 + z^2) + 22
}
gen_isosurface(
f = f,
scale = 0.1,
nx = 70
) |>
isocubesGrob(size = 2) |>
grid::grid.draw()
Run the code above in your browser using DataLab