matlab中的3D体图(体积可视化)

时间:2012-01-26 13:25:34

标签: matlab

我对MATLAB中的体积数据很少或没有经验, 我需要完成下一个任务: 我有3个向量(行):

x_ = vector(1:smpl:max_row,1);

y_ = vector(1:smpl:max_row,2);

z_ = vector(1:smpl:max_row,3);

是来自具有高度max_row的大3列数组向量的样本。 x_,y_,z_是3D图形的点 - 图形(体积)的表面点。它们代表应在matlab中绘制的3D主体。

我创建了线性网格:

%linear grid

a = -1.1:step:(-1.1+step*(length(x_)-1));

b = -1.1:step:(-1.1+step*(length(y_)-1));

c = -1.1:step:(-1.1+step*(length(z_)-1));


[x,y,z] = meshgrid(-1.1:step:(-1.1+step*(length(x_)-1)));

我还创建了数组v长度(x _)*长度(x _)*长度(x_),在3D主体表示功能点和'0'的单元格中包含'1'。

我试图进行插值:

vi = interp3(x,y,z,v,x,y,z,'nearest');

但是我已经创建了vi = v。

现在我需要在3D上绘制v数组并在

中形成3D体

http://www.mathworks.com/help/techdoc/ref/isonormals.html

例如。

我接下来这样做:

%plotting:

figure

p = patch(isosurface(x,y,z,v,1e-5,'verbose'),'FaceColor','green','EdgeColor','none');

grid on;

isonormals(v,p);

daspect([1 1 1])

view(3); 

axis tight;

camproj perspective;

camlight

lighting gouraud

colormap(hsv)

但是我得到的只是小矩形代替功能'1',它们没有像连接的图片那样连接。 我希望能够绘制由这些点包围的实体。

有谁知道问题是什么,如何从x,y,z,v数组中绘制3D体?

提前致谢。

图像:

http://imgur.com/Ulegj

1 个答案:

答案 0 :(得分:1)

试试这个,这将是一个很好的情节(虽然插入了一点):

x = vector(1:smpl:max_row,1);
y = vector(1:smpl:max_row,2);
z = vector(1:smpl:max_row,3);

% Settings
displaySurface = 1;
displayPoints = 0;
xres = 800; % Resolution, the higher, the smoother
yres = 800;         
cm = 'default'; % Colormap

% Axes Limits
xmin = min(x); 
ymin = min(y);
xmax = max(x); 
ymax = max(y); 
xi = linspace(xmin, xmax, xres);
yi = linspace(ymin, ymax, yres);

% Figure
myfig = figure('Position', [200 200 800 600]);

rotate3d off
[XI, YI] = meshgrid(xi, yi);
ZI = griddata(x, y, z, XI, YI, 'cubic');
mesh(XI,YI,ZI);
colormap(cm)

if(displaySurface == 1)
    hold on;
    surf(XI, YI, ZI, 'EdgeColor', 'none');
end
hold on;
xlabel('x');
ylabel('y'); 
zlabel('z'); 
title('Title', 'FontWeight', 'bold');
xlim([xmin xmax])
ylim([ymin ymax])
grid off;

if(displayPoints == 1)
    hold on
    plot3(x, y, z,'marker','p','markerfacecolor','w','linestyle','none')
    hidden off 
end