2015-02-24 64 views
0

讓我們考慮一下我有五個描述不同z層的磁場的2D矩陣。以三維視圖堆疊幾個曲面圖

data2_I<-matrix(c(1.0,1.0,0.6,0.6,0.7,0.9,0.9,0.5,0.5,0.5,0.7,0.9,0.9,0.6,0.3,0.4,0.7,0.9,0.9,0.7,0.5,0.5,0.6,0.9,0.9,0.7,0.6,0.6,1.0,1.0), nrow=5) 
Z = as.vector(data2_I) 
length(Z) 
XY=data.frame(x=as.numeric(gl(5,1,30)),y=as.numeric(gl(5,6,30))) 
t=Tps(XY,Z) 
surface(t) 

現在,這將是巨大的,如果我能得到一個三維圖,其中在不同的Z位置,這些表面繪製:一個漂亮的,平滑的二維曲面圖的版本可以按如下方式獲得。有沒有可能做到這一點?

+0

你應該包含與'TPS'相關的庫函數。另外,這個例子不是可重複的 - 如果你給我們一個獨立的例子(我們沒有'data2_I'),人們更可能幫助你。 – jbaums 2015-02-28 00:03:02

+0

Ups,對不起,我忘記了包含這些數據。 – 2015-03-01 01:02:19

回答

0

我找到了一種替代方法:使用包rgl I和函數表面3D,我可以在一個open3d窗口中堆疊多個3D表面圖。讓我們看一個小例子:

library("rgl") 
data2_I<-matrix(c(1.0,1.0,0.6,0.6,0.7,0.9,0.9,0.5,0.5,0.5,0.7,0.9,0.9,0.6,0.3,0.4,0.7,0.9,0.9,0.7,0.5,0.5,0.6,0.9,0.9,0.7,0.6,0.6,1.0,1.0), nrow=5) 
data0_I<-matrix(c(1.0,1.0,0.6,0.6,0.7,0.9,0.9,0.5,0.5,0.5,0.7,0.9,0.9,0.6,0.3,0.4,0.7,0.9,0.9,0.7,0.5,0.5,0.6,0.9,0.9,0.7,0.6,0.6,1.0,1.0), nrow=5) 
data1_I<-2*data0_I 
data2_I<-1/data1_I 

elv=0 
offs=5*elv+1 
z0 <- scale*data0_I   
z1 <- scale*data1_I 
z2 <- scale*data2_I 
x <- 1:nrow(z0) 
y <- 1:ncol(z0) 

palette <- colorRampPalette(c("blue","green","yellow", "red")) 
col.table <- palette(256) 
open3d(windowRect=c(50,50,800,800)) 
surface3d(x, y, elv*z0, color = col.table[cut(z0, 256)], back = "lines") 
surface3d(x, y, elv*z1+1*offs, color = col.table[cut(z1, 256)], back = "lines") 
surface3d(x, y, elv*z2+2*offs, color = col.table[cut(z2, 256)], back = "lines") 
axes3d() 
aspect3d(1,1,2) 

變量offsand ELV包括用於美容目的:取捨控制兩個面圖和高程surface3d-地塊的z軸應該如何擴展之間的空間。由於我想有一個沒有任何高程的2D曲面繪圖,我將它設置爲零。