3

我想使用 R 包 rgl 绘制相交曲面。我有一个 3D 数据数组,并且在常数“z”(数组 [,,n])处绘制曲面没有问题。但是,我不知道如何在同一个 rgl 图上绘制垂直表面 (array[n,,])。

示例:我可以使用以下方法设置数据:

dat <- list()
lengthout <- 20 # number of data in x, y and z
xrange <- seq(0,10,length.out=lengthout) # sets up dimensions
yrange <- xrange
zrange <- xrange

dat$x <- xrange # contain data in list
dat$y <- yrange
dat$z <- array(rnorm(lengthout^3),dim=c(lengthout,lengthout,lengthout)) # create random data

然后绘制数组 [,,n] 的多个平面部分,按值着色,如下所示:

for (n in seq(1,lengthout,4)){
  zlim <- range(dat$z[,,n],na.rm=T) # range of data in slice
  zlen <- diff(zlim) + 1 # 
  colorlut <- rainbow(zlen) # value color lookup table
  colmah <- colorlut[dat$z[,,n] -zlim[1]+1] # assign colors to value at each point
  surface3d(dat$x,dat$y,array(n,dim=c(lengthout,lengthout)), color=colmah,specular="black",alpha=(1-n/lengthout))
}

代码输出

有没有办法旋转各个表面的轴,以便我可以绘制这样的东西(注意常数“x”而不是“z”):

zlim <- range(dat$z[n,,],na.rm=T) # range of data in slice
zlen <- diff(zlim) + 1 # 
colorlut <- rainbow(zlen) # value color lookup table
colmah <- colorlut[dat$z[n,,] -zlim[1]+1] # assign colors to value at each point    
surface3d(dat$x,dat$y,array(n,dim=c(lengthout,lengthout)), color=colmah,specular="black")

干杯

4

1 回答 1

6

已解决:我没有使用surface3d(blah),而是使用了rgl.surface(blah, coords=c(3,1,2)):

dat <- list()
lengthout <- 20 # number of data in x, y and z
xrange <- seq(0,10,length.out=lengthout) # sets up dimensions
yrange <- xrange
zrange <- xrange

dat$x <- xrange # contain data in list
dat$y <- yrange
dat$z <- array(rnorm(lengthout^3),dim=c(lengthout,lengthout,lengthout)) # create random data

n=1
# Plot constant "z"
zlim <- range(dat$z[,,n],na.rm=T) # range of data in slice
zlen <- diff(zlim) + 1 # 
colorlut <- rainbow(zlen) # value color lookup table
colmah <- colorlut[dat$z[,,n] -zlim[1]+1] # assign colors to value at each point
rgl.surface(xrange,yrange,array(n,dim=c(lengthout,lengthout)), color=colmah,specular="black",alpha=(1-n/lengthout),coords=c(1,2,3))

# Plot constant "x"
zlim <- range(dat$z[n,,],na.rm=T) # range of data in slice
zlen <- diff(zlim) + 1 # 
colorlut <- rainbow(zlen) # value color lookup table
colmah <- colorlut[dat$z[n,,] -zlim[1]+1] # assign colors to value at each point
rgl.surface(yrange,zrange,array(n,dim=c(lengthout,lengthout)), color=colmah,specular="black",alpha=(1-n/lengthout),coords=c(3,1,2))

# Plot constant "y"
zlim <- range(dat$z[,n,],na.rm=T) # range of data in slice
zlen <- diff(zlim) + 1 # 
colorlut <- rainbow(zlen) # value color lookup table
colmah <- colorlut[dat$z[,n,] -zlim[1]+1] # assign colors to value at each point
rgl.surface(xrange,zrange,array(n,dim=c(lengthout,lengthout)), color=colmah,specular="black",alpha=(1-n/lengthout),coords=c(1,3,2))
axes3d()

在此处输入图像描述

于 2013-09-12T02:59:59.320 回答