本文介绍了插入“切断"R 曲面图中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using persp() to create a 3d plot (but I'm open to anything that will get the job done). Now I want to add a 2d field to make it clear where the 3d plot is above a specific Z value. Is there a way to achieve this? Ideally it would ideally be something like a semi transparent surface where you can see the mass under the surface vs over.

使用 persp 文档中的示例

Using the example from the persp documentation

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 轴的某个点对图形进行切片的字段?

How can I insert a field that slices the graph at a certain point of the z-axis?

推荐答案

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

How about this - there are a lot more possibilities using the rgl package, but it has a persp3d function for easy upgrade from the base graphics.

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)

产量:

这篇关于插入“切断"R 曲面图中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 09:10