Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. library(misc3d)
  2.  
  3. # Togliatti surface equation: f(x,y,z) = 0
  4. f <- function(x,y,z){
  5. w <- 1
  6. 64*(x-w)*
  7. (x^4-4*x^3*w-10*x^2*y^2-4*x^2*w^2+16*x*w^3-20*x*y^2*w+5*y^4+16*w^4-20*y^2*w^2) -
  8. 5*sqrt(5-sqrt(5))*(2*z-sqrt(5-sqrt(5))*w)*(4*(x^2+y^2-z^2)+(1+3*sqrt(5))*w^2)^2
  9. }
  10.  
  11. # make grid
  12. nx <- 220; ny <- 220; nz <- 220
  13. x <- seq(-5, 5, length=nx)
  14. y <- seq(-5, 5, length=ny)
  15. z <- seq(-4, 4, length=nz)
  16. g <- expand.grid(x=x, y=y, z=z)
  17.  
  18. # calculate voxel
  19. voxel <- array(with(g, f(x,y,z)), dim = c(nx,ny,nz))
  20.  
  21. # mask: keep points satisfying x^2+y^2+z^2 < 4.8^2, in order to
  22. # clip the surface to the ball of radius 4.8
  23. mask <- array(with(g, x^2+y^2+z^2 < 4.8^2), dim = c(nx,ny,nz))
  24.  
  25. # compute isosurface
  26. surf <- computeContour3d(voxel, maxvol=max(voxel), level=0, mask=mask, x=x, y=y, z=z)
  27.  
  28. # draw isosurface
  29. drawScene.rgl(makeTriangles(surf, smooth=TRUE))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement