r - 在 R 曲面图中插入 "cut off"字段

标签 r 3d surface rgl geometry-surface

我正在使用 persp() 创建 3d 绘图(但我愿意接受任何能够完成工作的东西)。现在我想添加一个 2d 字段,以明确 3d 图在特定 Z 值之上的位置。有办法实现这一点吗?理想情况下,它应该是类似半透明表面的东西,您可以在其中看到表面下方与上方的质量。

使用 persp 文档中的示例

f <- function(x, y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }

x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, f)
z[is.na(z)] <- 1

persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
      ltheta = 120, shade = 0.75, ticktype = "detailed",
      xlab = "X", ylab = "Y", zlab = "Sinc( r )"
) 

如何插入在 z 轴特定点对图形进行切片的字段?

最佳答案

这个怎么样 - 使用 rgl 包有更多的可能性,但它有一个 persp3d 功能,可以轻松地从基础图形升级.

library(rgl)

f <- function(x, y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, f)
z[is.na(z)] <- 1

persp3d(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue",
      ltheta = 120, shade = 0.75, ticktype = "detailed",
      xlab = "X", ylab = "Y", zlab = "Sinc( r )")

# Here we add a transparent purple square to mark the top

# x and y mark the corners of the purple square, z is its height
sqdf <- data.frame(x=c(-10,-10,10,10,-10),
                   y=c(-10, 10,10,-10,-10),
                   z=c(5,5,5,5,5))

# now draw the purple square, 
#    note:
#    -  the "add=T" parameter that appends it to the previous 3d-plot
#    -  the coord paramter tells it what two planes to use when 
#        tesselating the polygon into triangles 
#        (a necessary step and expensive to calculate)

polygon3d(sqdf$x,sqdf$y,sqdf$z,coord=c(1,2),alpha=0.5,color="purple",add=T)

产量:

enter image description here

关于r - 在 R 曲面图中插入 "cut off"字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36043991/

相关文章:

R - 如何将空的 POSIXct 列添加到已存在的 data.frame/tibble 中?

r - 为大型数据集从 R 中的 data.frame 中获取前 N 个排序元素

r - 如何处理带有双标题的Excel文件

iphone - glDrawElements VAO/VBO 在 iOS 上崩溃

c++ - 编写 3D 渲染浏览器插件

linux - Surface book 键盘无法在 scientific Linux 中使用

r - 在 R 版本 3.3.2 中安装 'forecast' 包时出错

OpenGL 体素游戏 - 避免透明度重叠

computational-geometry - 网格到网格的交叉点

Android Surfaceflinger 和 openGL ES