gpt4 book ai didi

r - R 中的垂直 3D 曲面

转载 作者:行者123 更新时间:2023-12-04 10:29:22 25 4
gpt4 key购买 nike

我想使用 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

然后绘制 array[,,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))
}

Output from code

有没有办法旋转各个表面的轴,以便我可以绘制类似这样的东西(注意常量“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")

干杯

最佳答案

已解决:我没有使用 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()

enter image description here

关于r - R 中的垂直 3D 曲面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18754439/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com