2011-10-06 17 views
3

嗨,任何人都可以給我一個簡單的例子,說明如何在MATLAB中使用isosurface函數。 如果您輸入help isosurface,則給出的示例非常混亂。在谷歌搜索沒有幫助,因爲沒有人在任何地方提供簡單的例子。他們都使用預定義的功能,如 flowisosurface函數MATLAB的用法

對於初學者,假設我有點(x,y,z)其中z = 0和在每個點我定義一個常數 函數f(x,y,z)=6。因此,如果我在等值6上使用等值面函數,我希望MATLAB給我一個三維圖,其中XY平面以某種顏色突出顯示,例如綠色。

回答

3

你給的例子很無趣,其實甚至有問題的。

通過摺疊所有點到z=0,您不再需要/不需要使用ISOSURFACE,而應該調用CONTOUR。即使是這樣,一個常數函數f(X,Y)=6將不顯示任何東西要麼...

由於@Jonas已經展示瞭如何使用等值面,這裏是輪廓函數的一個例子:

%# create a function to apply to all X/Y coordinates 
[X,Y] = meshgrid(-2:0.1:2,-1:0.1:1); 
f = @(X,Y) X.^3 -2*Y.^2 -3*X; 

%# plot the function surface 
subplot(121), surfc(X,Y,f(X,Y)) 
axis equal, daspect([1 1 3]) 

%# plot the iso-contour corresponding to where f=-1 
subplot(122), contour(X,Y,f(X,Y),[-1 -1]), 
axis square, title('Contour where f(X,Y)=-1') 

enter image description here

7

我不太明白你的榜樣,但這裏是你如何使用isosurface繪製球體:

%# create coordinates 
[xx,yy,zz] = meshgrid(-15:15,-15:15,-15:15); 
%# calculate distance from center of the cube 
rr = sqrt(xx.^2 + yy.^2 + zz.^2); 

%# create the isosurface by thresholding at a iso-value of 10 
isosurface(xx,yy,zz,rr,10); 

%# make sure it will look like a sphere 
axis equal 

enter image description here