Comments (7)
图的洞其实就是 xlim 和 ylim 没设置好。改成 xlim = c(-1.2, 1.2), ylim = c(-1.2, 1.2)
即可。我已经提交了 PR 到 yihui/fun:
画心的完整代码:
## 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.
这两个在我这里没问题。
> 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.
运行完代码都没有如上的警告,图也完全正确吗?
from msg.
未见警告。图都正确。
from msg.
I can run but there're 3 holes on the heart...
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.
@boltomli 我得到的结果和你一样,图有洞,还带警告
from msg.
我注意到我的问题,本质来源于警告,相关讨论见
https://stackoverflow.com/questions/47095169/
from msg.
Related Issues (20)
- 部分包有被提及但是没有使用 HOT 3
- 14 年后取消限制条款的出处? HOT 1
- 表 6.1 的显示有点乱 HOT 2
- ! Package caption Error: \caption outside float. HOT 1
- 转向 GithHub Action 测试
- 直播活动收集来的问题及谢大的回复 HOT 1
- Why not Noto? HOT 2
- 【数据】卫星图像的效果出不来 HOT 3
- 收集关于 MSG 的评论介绍
- 图书二维码
- 【封面】 MSG 书籍封面 HOT 4
- 此处编译 pdf 似乎已经无法通过,会生成一个 animategraphics HOT 1
- pandoc 和 rmarkdown 还支持 ascii_identifiers 吗? HOT 3
- 【第一版出版事宜】 HOT 14
- Travis-CI 报错集中处理 HOT 8
- 致谢 HOT 10
- LaTeX 输出的 pdf 代码格式里引号和中文字符之间的空格问题 HOT 4
- 1986 挑战者号失事的 O 型环故障与温度的关系图 HOT 6
- 部分目录链接错误
- 5.5.4 地图,建议更改显示地区
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msg.