MATLAB - 三维表面图 [英] MATLAB - 3D surface plot

查看:1029
本文介绍了MATLAB - 三维表面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在3D空间中20个数据点。在这里,你可以看到他们绘制:

I have 20 data points in 3D space. Here you can see them plotted:

clear all
close all
clc

Data = [97.4993     104.3297    0.7500  196.7021
        100.0000    105.0000    0.7500  290.9164
        100.0000    107.5000    0.7500  142.1626
        96.2569     106.4992    0.7500  143.3605
        97.5028     104.3317    1.0000  197.1111
        100.0000    105.0000    1.0000  290.4210
        100.0000    107.5000    1.0000  144.0155
        96.2530     106.4969    1.0000  144.0969
        98.7055     104.8295    0.7500  239.7734
        100.0000    106.2500    0.7500  214.6557
        98.0627     107.2455    0.7500  145.4154
        96.8781     105.4144    0.7500  161.7000
        97.5010     104.3307    0.8750  196.8880
        100.0000    105.0000    0.8750  290.6686
        100.0000    107.5000    0.8750  141.5008
        96.2549     106.4980    0.8750  144.0253
        98.7075     104.8300    1.0000  239.3455
        100.0000    106.2500    1.0000  215.2104
        98.0605     107.2449    1.0000  144.9653
        96.8779     105.4143    1.0000  161.4253];

x = Data(:,1); % x coordinates 
y = Data(:,2); % y coordinates 
z = Data(:,3); % z coordinates 
sigma = Data(:,4); % stress value at that point

for ii = 1:length(x)

    plot3(x(ii,1),y(ii,1),z(ii,1),'r*')
    hold on
    grid on
    text(x(ii,1),y(ii,1),z(ii,1),['   ' num2str(ii) '   '...
        num2str(sigma(ii))],'HorizontalAlignment','left','FontSize',12); 

end

此数据再presents 1 HEX20元(FEM)和它的20个节点。每个节点都有其旁边写着它的应力值(SIGMA)。的节点的编号遵循标准程序:

This data represents one HEX20 element (FEM) and its 20 nodes. Each node has its Stress value (sigma) written next to it. The numbering of the nodes follows the standard procedure:

我想绘制该元素的表面,如,示出的图片。然后(如果可能的话)我想基于节点(颜色映射)的应力值要着色的表面。最终的结果应该是这样的:

I would like to plot the surfaces of that element like it is shown in the picture. Then (if possible) I would like the surfaces to be coloured based on the stress value of the nodes (colour mapping). The end result should be something like this:

推荐答案

这里的建筑补丁的另一种方式。您指定的点(顶点)的结构,那么面(这点做的,他们包括),然后是矢量的颜色(你的西格玛值),那么你就发很多补丁功能,将剩下的事情。

Here's another way of building patches. You specify a structure with the points (vertices), then the faces (which points do they include), then a vector of color (your sigma values), then you send the lot to the patch function which will take care of the rest.

然后就敲定细节(透明度,边缘颜色,画出你的观点和文字等)

Then you finalise the details (transparency, edge color, plot your points and text etc ...)

fv.vertices = Data(:,1:3);
fv.faces = [...
    1  9 2 10 3 11 4 12 ;
    1  9 2 14 6 17 5 13 ;
    5 17 6 18 7 19 8 20 ;
    2 10 3 15 7 18 6 14 ;
    3 11 4 16 8 19 7 15 ;
    4 12 1 13 5 20 8 16 ...
    ] ;
fv.facevertexcdata = Data(:,4);

hold on
hp  = patch(fv,'CDataMapping','scaled','EdgeColor',[.7 .7 .7],'FaceColor','interp','FaceAlpha',1)    
hp3 = plot3(x,y,z,'ok','Markersize',6,'MarkerFaceColor','r')

for ii = 1:length(x)
    text(x(ii,1),y(ii,1),z(ii,1),{sprintf('   #%d - \\sigma:%4.1f',ii,sigma(ii))},...
        'HorizontalAlignment','left','FontSize',8,'FontWeight','bold'); 
end
view(-27,26)
axis equal
axis off
colorbar south

意志产生:

编辑: 它是略高于要求比较繁琐 convhull 找信封,但它有尊重你的元素的实际形状(不关闭节点9和附近的向内体积小的优点;。17)

It is slightly more tedious than asking convhull to find the envelope, but it has the merit of respecting the actual shape of your element (not closing the inward small volume near nodes 9 & 17).

要避免当补丁面孔并不完美的平面图形呈现故障,您可以定义的面孔,使他们都将是完美的平面。这意味着定义更多的面孔(我们有分裂个个2),但它绕着小故障,现在所有的面孔都是可见的。 所以,如果你想要去的方式,只需更换面对上述的定义是:

To avoid the graphic rendering glitch when the patch faces are not perfectly planar, you can define the faces so they will all be perfectly planar. It means defining more faces (we have to split all of them in 2), but it goes round the glitch and now all your faces are visible. So if you want to go that way, just replace the face definition above by:

fv.faces = [...
     1  9 11 4 12 ;
     9  2 10 3 11 ;
     1  9 17 5 13 ;
     9  2 14 6 17 ;
     2 10 18 6 14 ;
    10  3 15 7 18 ;
     3 11 19 7 15 ;
    11  4 16 8 19 ;
     4 12 20 8 16 ;
    12  1 13 5 20 ;
     5 17 19 8 20 ;
    17  6 18 7 19 ] ;

有定义面孔的方法不止一种,只是注意到面临向量的每一行,就是点定义一个区域的继承(面对将关闭自行关闭,无需重复第一点,最终收表面)。 我们从脸上去了,8点到面连得5分...如果你想播放/完善模型,您可以尝试使用3个点的面孔,它的工作方式相同。

There are more than one way to define the faces, just notice that each line of the faces vector, is a succession of point defining an area (the face will close itself down, no need to repeat the first point in the end to close the surface). We went from faces with 8 points to faces with 5 points ... if you want to play/refine your model, you could try using 3 points faces, it would work the same way.

这篇关于MATLAB - 三维表面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆