Giter VIP home page Giter VIP logo

Comments (7)

pzhaonet avatar pzhaonet commented on July 26, 2024 3

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 <[email protected]>
## 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)

from msg.

pzhaonet avatar pzhaonet commented on July 26, 2024

这两个在我这里没问题。

> 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

from msg.

XiangyunHuang avatar XiangyunHuang commented on July 26, 2024

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

from msg.

pzhaonet avatar pzhaonet commented on July 26, 2024

未见警告。图都正确。

from msg.

boltomli avatar boltomli commented on July 26, 2024

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)

from msg.

XiangyunHuang avatar XiangyunHuang commented on July 26, 2024

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

from msg.

XiangyunHuang avatar XiangyunHuang commented on July 26, 2024

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

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

tylermorganwall/rayshader#26

from msg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.