XiangyunHuang / msg

:book: 现代统计图形(人民邮电出版社出版) Modern Statistical Graphics

Home Page:https://bookdown.org/xiangyun/msg

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

【第五章 系统】rgl 动态图形两个 demo 运行报错或警告

XiangyunHuang opened this issue · comments

animation 包内的两个动画运行起来报错了 @yihui @pzhaonet 帮忙看下能否在其它平台上运行

我计划能在网页中插入动画的尽量插入,而不是放一个截图,能动态生成最好

demo 1

demo("rgl_animation", package = "animation")

        demo(rgl_animation)
        ---- ~~~~~~~~~~~~~

Type  <Return>   to start : 

> ## how to use saveLatex() with the rgl package
> 
> library(animation)

> if (require('rgl')) {
+   saveLatex({
+     ## ajust the view
+     uM =
+       matrix(c(-0.37, -0.51, -0.77, 0, -0.73, 0.67,
+                -0.10, 0, 0.57, 0.53, -0.63, 0, 0, 0, 0, 1),
+              nrow = 4, ncol = 4)
+     
+     ## note the width and height are 500px respectively
+     open3d(userMatrix = uM, windowRect = c(30, 30, 530, 530))
+     plot3d(pollen[, 1:3])
+     zm = seq(1, .05, length = 20)
+     par3d(zoom = 1)
+     
+     ## the most important argument is use.dev = FALSE!
+     ## and the file extension should be 'png', since we are using rgl.snapshot()
+     for (i in 1:length(zm)) {
+       par3d(zoom = zm[i])
+       rgl.snapshot(sprintf(ani.options('img.fmt'), i))
+     }
+     rgl.close()
+   }, img.name='pollen_demo', use.dev=FALSE,
+             ani.type='png', interval = .2,
+             ani.opts = 'controls,width=3in',
+             latex.filename='rgl_pollen_animation.tex',
+             caption = 'Zoom in a 3D scatter plot to see the truth.',
+             overwrite = FALSE)
+   
+ } else warning('You have to install the rgl package first: install.packages("rgl")')
Loading required package: rgl
Error in rgl.snapshot(sprintf(ani.options("img.fmt"), i)) : 
  pixmap save format not supported in this build

在 RGUI 里运行能画出图来,同时伴随上述警告,而放在 bookdown 里运行,出不来图

demo 2

 demo('ChinaHeart3D', package = 'fun')


        demo(ChinaHeart3D)
        ---- ~~~~~~~~~~~~

> ## 3D heart with a Chinese five-star flag
> ## Author: Yixuan Qiu <yixuan.qiu@cos.name>
> ## original code in a Chinese forum: http://cos.name/cn/topic/16743
> ## this code was written to celebrate China's 60 anniversary
> if (!require("rgl")) stop("You need the rgl package to generate the 3D heart!")

> xtheta = function(x, theta, y, w = 0, tt = 0) {
+     (x^2 + (x * tan(theta))^2 + 2 * y^2 + 0.1 * cos(w * tt) -
+      0.9)^3 - (x^2 + y^2/9) * (x * tan(theta))^3
+ }

> fz = function(z, x, y, w = 0, tt = 0) {
+     (x^2 + 2 * y^2 + z^2 + 0.1 * cos(w * tt) - 0.9)^3 - (x^2 + y^2/9) * z^3
+ }

> n = 100

> y = seq(-2, 2, length.out = n)

> y0 = xx = zz = NULL

> for (i in 1:length(y)) {
+     theta = seq(-pi/2, 1.5 * pi, length.out = n)
+     solvex = function(theta, y) {
+         if (theta == -pi/2 | theta == pi/2 | theta == 1.5 * pi) {
+             return(0)
+         } else if (theta > -pi/2 & theta < pi/2) {
+             interval = c(0, 2)
+         } else {
+             interval = c(-2, 0)
+         }
+         x.root = uniroot(xtheta, interval, theta, y)$root
+         return(x.root)
+     }
+     if (xtheta(0, pi/4, y[i]) * xtheta(2, pi/4, y[i]) > 0)
+         next
+     y0 = c(y0, y[i])
+     x = sapply(theta, solvex, y[i])
+     zplus = uniroot(fz, c(0, 2), 0, y[i])$root
+     zminus = uniroot(fz, c(-2, 0), 0, y[i])$root
+     z = numeric(n)
+     z[x != 0] = x[x != 0] * tan(theta[x != 0])
+     z[x == 0] = (theta[x == 0] == pi/2) * zplus + (theta[x == 0] != pi/2) * zminus
+     xx = cbind(xx, x)
+     zz = cbind(zz, z)
+ }

> yy = matrix(rep(y0, n), n, length(y0), byrow = TRUE)

> library(rgl)

> persp3d(zz, xx, yy, col = "red", xlim = c(-1, 1), ylim = c(-1, 1), zlim = c(-1, 1),
+         axes = FALSE, box = FALSE, xlab = "", ylab = "", zlab = "")

> fy = function(y, pars) {
+     z = pars[1]
+     x = pars[2]
+     w = pars[3]
+     tt = pars[4]
+     (x^2 + 2 * y^2 + z^2 + 0.1 * cos(w * tt) - 0.9)^3 - (x^2 + y^2/9) * z^3
+ }

> gety = function(z, x, interval = c(0.01, 1), w = 0, tt = 0) {
+     mpars = cbind(z, x, w, tt)
+     solvey = function(pars) {
+         if (fy(interval[1], pars) * fy(interval[2], pars) > 0) {
+             return(NA)
+         } else {
+             y = uniroot(fy, interval, pars)$root
+         }
+     }
+     y = apply(mpars, 1, solvey)
+     return(y)
+ }

> x0 = z0 = seq(-1, 1, length.out = n)

> y0 = outer(z0, x0, gety)

> persp3d(x = z0, y = x0, z = y0, zlim = c(-1, 1), col = "white",
+         texture = system.file("img", "flag.png", package = "fun"), add = TRUE)

> persp3d(x = z0, y = x0, z = -y0, zlim = c(-1, 1), col = "red", add = TRUE)
Warning messages:
1: In rgl.material(...) : RGL: Pixmap load: file format unsupported
2: In rgl.material(...) : RGL: Pixmap load: failed

在 RGUI 里没有图,只有上述警告

Warning messages:
1: In rgl.material(...) : RGL: Pixmap load: file format unsupported
2: In rgl.material(...) : RGL: Pixmap load: failed

运行环境

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8.1 x64 (build 9600)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 
[2] LC_CTYPE=Chinese (Simplified)_China.936   
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods  
[8] base     

other attached packages:
[1] animation_2.6   htmlwidgets_1.3 rgl_0.100.26   

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2              digest_0.6.20           later_0.8.0            
 [4] mime_0.7                R6_2.4.0                xtable_1.8-4           
 [7] jsonlite_1.6            magrittr_1.5            evaluate_0.14          
[10] miniUI_0.1.1.1          promises_1.0.1          rmarkdown_1.14         
[13] webshot_0.5.1           tools_3.6.1             manipulateWidget_0.10.0
[16] crosstalk_1.0.0         shiny_1.3.2             yaml_2.2.0             
[19] xfun_0.8                httpuv_1.5.1            compiler_3.6.1         
[22] htmltools_0.3.6         knitr_1.24             

这两个在我这里没问题。

> devtools::session_info()
- Session info ---------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.1 (2019-07-05)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       Europe/Berlin               
 date     2019-08-16                  

- Packages -------------------------------------------------------------------------------------------
 package          * version  date       lib source        
 animation        * 2.6      2018-12-11 [1] CRAN (R 3.6.1)
 assertthat         0.2.1    2019-03-21 [1] CRAN (R 3.6.1)
 backports          1.1.4    2019-04-10 [1] CRAN (R 3.6.0)
 bookdown           0.12     2019-07-11 [1] CRAN (R 3.5.3)
 callr              3.3.1    2019-07-18 [1] CRAN (R 3.6.1)
 cli                1.1.0    2019-03-19 [1] CRAN (R 3.6.1)
 colorspace         1.4-1    2019-03-18 [1] CRAN (R 3.6.1)
 crayon             1.3.4    2017-09-16 [1] CRAN (R 3.6.1)
 crosstalk          1.0.0    2016-12-21 [1] CRAN (R 3.6.1)
 desc               1.2.0    2018-05-01 [1] CRAN (R 3.6.1)
 devtools           2.1.0    2019-07-06 [1] CRAN (R 3.5.3)
 digest             0.6.20   2019-07-04 [1] CRAN (R 3.6.1)
 dplyr              0.8.3    2019-07-04 [1] CRAN (R 3.6.1)
 evaluate           0.14     2019-05-28 [1] CRAN (R 3.6.1)
 filehash           2.4-2    2019-04-17 [1] CRAN (R 3.6.0)
 formatR          * 1.7      2019-06-11 [1] CRAN (R 3.6.1)
 fs                 1.3.1    2019-05-06 [1] CRAN (R 3.5.3)
 ggplot2          * 3.2.1    2019-08-10 [1] CRAN (R 3.6.1)
 glue               1.3.1    2019-03-12 [1] CRAN (R 3.6.1)
 gtable             0.3.0    2019-03-25 [1] CRAN (R 3.6.1)
 htmltools          0.3.6    2017-04-28 [1] CRAN (R 3.6.1)
 htmlwidgets        1.3      2018-09-30 [1] CRAN (R 3.6.1)
 httpuv             1.5.1    2019-04-05 [1] CRAN (R 3.6.1)
 jsonlite           1.6      2018-12-07 [1] CRAN (R 3.6.1)
 knitr              1.24     2019-08-08 [1] CRAN (R 3.6.1)
 labeling           0.3      2014-08-23 [1] CRAN (R 3.6.0)
 later              0.8.0    2019-02-11 [1] CRAN (R 3.6.1)
 lazyeval           0.2.2    2019-03-15 [1] CRAN (R 3.6.1)
 magick             2.1      2019-07-25 [1] CRAN (R 3.6.1)
 magrittr           1.5      2014-11-22 [1] CRAN (R 3.6.1)
 manipulateWidget   0.10.0   2018-06-11 [1] CRAN (R 3.6.1)
 memoise            1.1.0    2017-04-21 [1] CRAN (R 3.5.2)
 mime               0.7      2019-06-11 [1] CRAN (R 3.6.0)
 miniUI             0.1.1.1  2018-05-18 [1] CRAN (R 3.6.1)
 munsell            0.5.0    2018-06-12 [1] CRAN (R 3.6.1)
 packrat            0.5.0    2018-11-14 [1] CRAN (R 3.5.3)
 pillar             1.4.2    2019-06-29 [1] CRAN (R 3.6.1)
 pkgbuild           1.0.4    2019-08-05 [1] CRAN (R 3.6.1)
 pkgconfig          2.0.2    2018-08-16 [1] CRAN (R 3.6.1)
 pkgload            1.0.2    2018-10-29 [1] CRAN (R 3.6.1)
 prettyunits        1.0.2    2015-07-13 [1] CRAN (R 3.6.1)
 processx           3.4.1    2019-07-18 [1] CRAN (R 3.6.1)
 promises           1.0.1    2018-04-13 [1] CRAN (R 3.6.1)
 ps                 1.3.0    2018-12-21 [1] CRAN (R 3.6.1)
 purrr              0.3.2    2019-03-15 [1] CRAN (R 3.6.1)
 R6                 2.4.0    2019-02-14 [1] CRAN (R 3.6.1)
 Rcpp               1.0.2    2019-07-25 [1] CRAN (R 3.6.1)
 remotes            2.1.0    2019-06-24 [1] CRAN (R 3.6.1)
 rgl              * 0.100.26 2019-07-08 [1] CRAN (R 3.6.1)
 rlang              0.4.0    2019-06-25 [1] CRAN (R 3.6.1)
 rmarkdown          1.14     2019-07-12 [1] CRAN (R 3.6.1)
 rprojroot          1.3-2    2018-01-03 [1] CRAN (R 3.6.1)
 rsconnect          0.8.15   2019-07-22 [1] CRAN (R 3.6.1)
 rstudioapi         0.10     2019-03-19 [1] CRAN (R 3.6.1)
 scales             1.0.0    2018-08-09 [1] CRAN (R 3.6.1)
 sessioninfo        1.1.1    2018-11-05 [1] CRAN (R 3.5.2)
 shiny              1.3.2    2019-04-22 [1] CRAN (R 3.6.1)
 testthat           2.2.1    2019-07-25 [1] CRAN (R 3.6.1)
 tibble             2.1.3    2019-06-06 [1] CRAN (R 3.6.1)
 tidyselect         0.2.5    2018-10-11 [1] CRAN (R 3.6.1)
 tikzDevice       * 0.12.3   2019-08-07 [1] CRAN (R 3.6.1)
 usethis            1.5.1    2019-07-04 [1] CRAN (R 3.5.3)
 webshot            0.5.1    2018-09-28 [1] CRAN (R 3.6.1)
 withr              2.1.2    2018-03-15 [1] CRAN (R 3.6.1)
 xfun               0.8      2019-06-25 [1] CRAN (R 3.6.1)
 xtable             1.8-4    2019-04-21 [1] CRAN (R 3.6.1)
 yaml               2.2.0    2018-07-25 [1] CRAN (R 3.6.0)

[1] D:/Program Files/R-3.6.1/library

运行完代码都没有如上的警告,图也完全正确吗?

未见警告。图都正确。

I can run but there're 3 holes on the heart...

image

warning messages:

[25853:25909:0819/183829.702134:ERROR:gles2_cmd_decoder.cc(10168)] [.WebGL-0x2b9acb0]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.
[25853:25909:0819/183829.708903:ERROR:gles2_cmd_decoder.cc(10168)] [.WebGL-0x2b9acb0]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering.
"[.WebGL-0x2b9acb0]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering."
"[.WebGL-0x2b9acb0]RENDER WARNING: texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering."
─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.1 (2019-07-05)
 os       Manjaro Linux               
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  zh_CN.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Asia/Shanghai               
 date     2019-08-19                  

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package          * version  date       lib source        
 animation        * 2.6      2018-12-11 [1] CRAN (R 3.6.1)
 assertthat         0.2.1    2019-03-21 [1] CRAN (R 3.6.1)
 backports          1.1.4    2019-04-10 [1] CRAN (R 3.6.1)
 bookdown           0.12     2019-07-11 [1] CRAN (R 3.6.1)
 callr              3.3.1    2019-07-18 [1] CRAN (R 3.6.1)
 cli                1.1.0    2019-03-19 [1] CRAN (R 3.6.1)
 colorspace         1.4-1    2019-03-18 [1] CRAN (R 3.6.1)
 crayon             1.3.4    2017-09-16 [1] CRAN (R 3.6.1)
 crosstalk          1.0.0    2016-12-21 [1] CRAN (R 3.6.1)
 desc               1.2.0    2018-05-01 [1] CRAN (R 3.6.1)
 devtools           2.1.0    2019-07-06 [1] CRAN (R 3.6.1)
 digest             0.6.20   2019-07-04 [1] CRAN (R 3.6.1)
 dplyr              0.8.3    2019-07-04 [1] CRAN (R 3.6.1)
 evaluate           0.14     2019-05-28 [1] CRAN (R 3.6.1)
 formatR          * 1.7      2019-06-11 [1] CRAN (R 3.6.1)
 fs                 1.3.1    2019-05-06 [1] CRAN (R 3.6.1)
 ggplot2          * 3.2.1    2019-08-10 [1] CRAN (R 3.6.1)
 glue               1.3.1    2019-03-12 [1] CRAN (R 3.6.1)
 gtable             0.3.0    2019-03-25 [1] CRAN (R 3.6.1)
 hexbin             1.27.3   2019-05-14 [1] CRAN (R 3.6.1)
 htmltools          0.3.6    2017-04-28 [1] CRAN (R 3.6.1)
 htmlwidgets        1.3      2018-09-30 [1] CRAN (R 3.6.1)
 httpuv             1.5.1    2019-04-05 [1] CRAN (R 3.6.1)
 jsonlite           1.6      2018-12-07 [1] CRAN (R 3.6.1)
 KernSmooth       * 2.23-15  2015-06-29 [2] CRAN (R 3.6.1)
 knitr              1.24     2019-08-08 [1] CRAN (R 3.6.1)
 labeling           0.3      2014-08-23 [1] CRAN (R 3.6.1)
 later              0.8.0    2019-02-11 [1] CRAN (R 3.6.1)
 lattice          * 0.20-38  2018-11-04 [2] CRAN (R 3.6.1)
 lazyeval           0.2.2    2019-03-15 [1] CRAN (R 3.6.1)
 magick             2.1      2019-07-25 [1] CRAN (R 3.6.1)
 magrittr           1.5      2014-11-22 [1] CRAN (R 3.6.1)
 manipulateWidget   0.10.0   2018-06-11 [1] CRAN (R 3.6.1)
 markdown           1.1      2019-08-07 [1] CRAN (R 3.6.1)
 MASS               7.3-51.4 2019-03-31 [2] CRAN (R 3.6.1)
 memoise            1.1.0    2017-04-21 [1] CRAN (R 3.6.1)
 mime               0.7      2019-06-11 [1] CRAN (R 3.6.1)
 miniUI             0.1.1.1  2018-05-18 [1] CRAN (R 3.6.1)
 munsell            0.5.0    2018-06-12 [1] CRAN (R 3.6.1)
 mvtnorm          * 1.0-11   2019-06-19 [1] CRAN (R 3.6.1)
 pillar             1.4.2    2019-06-29 [1] CRAN (R 3.6.1)
 pkgbuild           1.0.4    2019-08-05 [1] CRAN (R 3.6.1)
 pkgconfig          2.0.2    2018-08-16 [1] CRAN (R 3.6.1)
 pkgload            1.0.2    2018-10-29 [1] CRAN (R 3.6.1)
 plyr               1.8.4    2016-06-08 [1] CRAN (R 3.6.1)
 prettyunits        1.0.2    2015-07-13 [1] CRAN (R 3.6.1)
 processx           3.4.1    2019-07-18 [1] CRAN (R 3.6.1)
 promises           1.0.1    2018-04-13 [1] CRAN (R 3.6.1)
 ps                 1.3.0    2018-12-21 [1] CRAN (R 3.6.1)
 purrr              0.3.2    2019-03-15 [1] CRAN (R 3.6.1)
 R6                 2.4.0    2019-02-14 [1] CRAN (R 3.6.1)
 Rcpp               1.0.2    2019-07-25 [1] CRAN (R 3.6.1)
 remotes            2.1.0    2019-06-24 [1] CRAN (R 3.6.1)
 reshape2           1.4.3    2017-12-11 [1] CRAN (R 3.6.1)
 rgl              * 0.100.26 2019-07-08 [1] CRAN (R 3.6.1)
 rlang              0.4.0    2019-06-25 [1] CRAN (R 3.6.1)
 rmarkdown          1.14     2019-07-12 [1] CRAN (R 3.6.1)
 rprojroot          1.3-2    2018-01-03 [1] CRAN (R 3.6.1)
 rstudioapi         0.10     2019-03-19 [1] CRAN (R 3.6.1)
 scales             1.0.0    2018-08-09 [1] CRAN (R 3.6.1)
 sessioninfo        1.1.1    2018-11-05 [1] CRAN (R 3.6.1)
 shiny              1.3.2    2019-04-22 [1] CRAN (R 3.6.1)
 stringi            1.4.3    2019-03-12 [1] CRAN (R 3.6.1)
 stringr            1.4.0    2019-02-10 [1] CRAN (R 3.6.1)
 testthat           2.2.1    2019-07-25 [1] CRAN (R 3.6.1)
 tibble             2.1.3    2019-06-06 [1] CRAN (R 3.6.1)
 tidyselect         0.2.5    2018-10-11 [1] CRAN (R 3.6.1)
 usethis            1.5.1    2019-07-04 [1] CRAN (R 3.6.1)
 viridisLite        0.3.0    2018-02-01 [1] CRAN (R 3.6.1)
 webshot            0.5.1    2018-09-28 [1] CRAN (R 3.6.1)
 withr              2.1.2    2018-03-15 [1] CRAN (R 3.6.1)
 xfun               0.8      2019-06-25 [1] CRAN (R 3.6.1)
 xtable             1.8-4    2019-04-21 [1] CRAN (R 3.6.1)
 yaml               2.2.0    2018-07-25 [1] CRAN (R 3.6.1)

@boltomli 我得到的结果和你一样,图有洞,还带警告

chineseheart

图的洞其实就是 xlim 和 ylim 没设置好。改成 xlim = c(-1.2, 1.2), ylim = c(-1.2, 1.2) 即可。我已经提交了 PR 到 yihui/fun:

yihui/fun#10 (comment)

画心的完整代码:

## 3D heart with a Chinese five-star flag
## Author: Yixuan Qiu <yixuan.qiu@cos.name>
## original code in a Chinese forum: http://cos.name/cn/topic/16743
## this code was written to celebrate China's 60 anniversary
if (!require("rgl")) stop("You need the rgl package to generate the 3D heart!")
xtheta = function(x, theta, y, w = 0, tt = 0) {
    (x^2 + (x * tan(theta))^2 + 2 * y^2 + 0.1 * cos(w * tt) -
     0.9)^3 - (x^2 + y^2/9) * (x * tan(theta))^3
}
fz = function(z, x, y, w = 0, tt = 0) {
    (x^2 + 2 * y^2 + z^2 + 0.1 * cos(w * tt) - 0.9)^3 - (x^2 + y^2/9) * z^3
}
n = 100
y = seq(-1, 1, length.out = n)
y0 = xx = zz = NULL
for (i in 1:length(y)) {
    theta = seq(-pi/2, 1.5 * pi, length.out = n)
    solvex = function(theta, y) {
        if (theta == -pi/2 | theta == pi/2 | theta == 1.5 * pi) {
            return(0)
        } else if (theta > -pi/2 & theta < pi/2) {
            interval = c(0, 2)
        } else {
            interval = c(-2, 0)
        }
        x.root = uniroot(xtheta, interval, theta, y)$root
        return(x.root)
    }
    if (xtheta(0, pi/4, y[i]) * xtheta(2, pi/4, y[i]) > 0)
        next
    y0 = c(y0, y[i])
    x = sapply(theta, solvex, y[i])
    zplus = uniroot(fz, c(0, 2), 0, y[i])$root
    zminus = uniroot(fz, c(-2, 0), 0, y[i])$root
    z = numeric(n)
    z[x != 0] = x[x != 0] * tan(theta[x != 0])
    z[x == 0] = (theta[x == 0] == pi/2) * zplus + (theta[x == 0] != pi/2) * zminus
    xx = cbind(xx, x)
    zz = cbind(zz, z)
}
yy = matrix(rep(y0, n), n, length(y0), byrow = TRUE)
library(rgl)
persp3d(zz, xx, yy, col = "red", xlim = c(-1.2, 1.2), ylim = c(-1.2, 1.2), zlim = c(-1, 1),
        axes = FALSE, box = FALSE, xlab = "", ylab = "", zlab = "")

fy = function(y, pars) {
    z = pars[1]
    x = pars[2]
    w = pars[3]
    tt = pars[4]
    (x^2 + 2 * y^2 + z^2 + 0.1 * cos(w * tt) - 0.9)^3 - (x^2 + y^2/9) * z^3
}
gety = function(z, x, interval = c(0.01, 1), w = 0, tt = 0) {
    mpars = cbind(z, x, w, tt)
    solvey = function(pars) {
        if (fy(interval[1], pars) * fy(interval[2], pars) > 0) {
            return(NA)
        } else {
            y = uniroot(fy, interval, pars)$root
        }
    }
    y = apply(mpars, 1, solvey)
    return(y)
}
x0 = z0 = seq(-1, 1, length.out = n)
y0 = outer(z0, x0, gety)
persp3d(x = z0, y = x0, z = y0, zlim = c(-1, 1), col = "white",
        texture = system.file("img", "flag.png", package = "fun"), add = TRUE)
persp3d(x = z0, y = x0, z = -y0, zlim = c(-1, 1), col = "red", add = TRUE)

我注意到我的问题,本质来源于警告,相关讨论见

https://stackoverflow.com/questions/47095169/

tylermorganwall/rayshader#26