coolbutuseless / isocubes

Other
66 stars 2 forks source link

How to rotate a grob of isocubes? #5

Closed stla closed 2 weeks ago

stla commented 1 year ago

Hello,

Here is my grob of isocubes:

isocubes_doubleTrumpet

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)
stla commented 1 year ago

I've found a way: apply a rotation to the arguments x, y, z.

stla commented 1 year ago

... but then the result is not perfect. Is there another way?

spiderCage_isocubes

coolbutuseless commented 2 weeks ago

This is the only way to do this with the current system. Great looking animation!