简体   繁体   English

如何用R绘制3D矩阵的3D曲面

[英]How to plot a 3D surface of a 3D matrix with R

I have 3D matrix of floating point numbers and I would like to produce a smoothed 3D surface of this matrix using R. Any suggestions are welcome. 我有浮点数的3D矩阵,我想使用R生成此矩阵的平滑3D曲面。欢迎提出任何建议。 Thanks 谢谢

Now I am using scatterplot3d ... But this function did not produce a smoothed surface 现在我正在使用scatterplot3d ...但是此函数没有产生平滑的表面

x<-read.table("/Users/me/Desktop/data.txt")
scatterplot3d(x$V1, x$V2, x$V3, highlight.3d = TRUE, angle = 30, col.axis = "blue", col.grid = "lightblue", cex.axis = 1.3, cex.lab = 1.1, pch = 20)

If you are able to create a 2D matrix (x,y) with the value being the z-axis value you could use the following 如果您能够创建2D矩阵(x,y),并且该值是z轴值,则可以使用以下命令

persp

Here is an example from R Graph Gallery. 这是R Graph Gallery中的示例。 persp example 例子

require(misc3d)

a <- 2/5

wsqr <-  1 - a^2
w <- sqrt(wsqr)
denom <- function(a,w,u,v) a*((w*cosh(a*u))^2 + (a*sin(w*v))^2)

fx <- function(u,v) -u + (2*wsqr*cosh(a*u)*sinh(a*u)/denom(a,w,u,v))
fy <- function(u,v) 2*w*cosh(a*u)*(-(w*cos(v)*cos(w*v)) - (sin(v)*sin(w*v)))/denom(a,w,u,v)
fz = function(u,v) 2*w*cosh(a*u)*(-(w*sin(v)*cos(w*v)) + (cos(v)*sin(w*v)))/denom(a,w,u,v)


parametric3d(fx = fx, fy = fy, fz = fz, 
             umin = -17, 
             umax = 17, 
             vmin = -77, 
             vmax = 77, 
             n = 100,
             color = c("grey17","grey21","red4","darkred","red4","grey21","grey17"),
             engine = "rgl")

在此处输入图片说明

I think that mba.surf from the MBA package would be a good choice for the smoothing, and as larrydag above suggests, persp would be good to image it. 我认为, MBA软件包中的mba.surf将是平滑的一个不错的选择,并且正如上面的persp所建议的那样, persp可以很好地对其进行成像。 The code below is from the help page for the mba.surf function (swap LIDAR for your 3 column dataframe): 以下代码来自mba.surf函数的帮助页面 (将LIDAR替换为3列数据 ):

data(LIDAR)
mba.int <- mba.surf(LIDAR, 300, 300, extend=TRUE)$xyz.est
# Two ways of imaging....
image(mba.int, xaxs="r", yaxs="r")
persp(mba.int, theta = 135, phi = 30, col = "green3", scale = FALSE,
  ltheta = -120, shade = 0.75, expand = 10, border = NA, box = FALSE)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM