isocubes
isocubes copied to clipboard
How to rotate a grob of isocubes?
Hello,
Here is my grob of isocubes:
How can I rotate it?
library(grid)
library(isocubes)
A <- cospi(3/4); B <- sinpi(3/4)
f <- function(x, y, z) {
z^4*B^2 + 4*x*y^2*A*B^2 + x*z^2*A*B^2 - 2*z^4*A - 4*x*y^2*B^2 - x*z^2*B^2 +
3*z^2*A*B^2 - 2*z^4 - x*A*B^2 - 2*z^2*A + x*B^2 + A*B^2 + 2*z^2 - B^2
}
N <- 31
x <- y <- z <- seq(-N, N)
coords <- expand.grid(x = x, y = y, z = z)
keep <- with(
coords,
sqrt(x*x + y*y + z*z) < 10*3 & f(x/10, y/10, z/10) < 0 & f(x/10, y/10, z/10) > -2
)
coords <- coords[keep,]
fill <-
rgb(red = 1 + coords$x/N, 1 + coords$y/N, 1 + coords$z/N, maxColorValue = 2)
cubes <- isocubesGrob(coords, fill, xo = 0.5, yo = 0.5, ysize = 1/100)
grid.newpage()
grid.draw(cubes)
I've found a way: apply a rotation to the arguments x, y, z.
... but then the result is not perfect. Is there another way?
This is the only way to do this with the current system. Great looking animation!