4

我有浮点数的 3D 矩阵,我想使用 R 生成该矩阵的平滑 3D 表面。欢迎提出任何建议。谢谢

现在我正在使用 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)
4

3 回答 3

2
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")

在此处输入图像描述

于 2013-03-07T16:31:04.017 回答
2

我认为mba.surfMBA包装中提取平滑是一个不错的选择,正如上面的 larrydag 所建议的那样,persp对它进行成像会很好。下面的代码来自mba.surf函数的帮助页面(为您的 3 列数据框交换 LIDAR):

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)

在此处输入图像描述

于 2013-03-07T16:47:02.513 回答
2

如果您能够创建一个二维矩阵 (x,y),其值为 z 轴值,您可以使用以下

persp

这是来自 R Graph Gallery 的示例。例子

于 2013-03-07T16:28:46.940 回答