生成网格并细化三角形的网格 [英] Generate mesh and refine mesh of triangles

查看:58
本文介绍了生成网格并细化三角形的网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找到一种方法来对三角形进行网格划分,然后使用细化"进行细化.我原始三角形的顶点存储在大小为nb_points * 2的矩阵内.我的人脸存储在 nb_faces * 3 矩阵中.每个面部的数据存储在nb_face * 1矩阵中.网格划分是通过使用三角形线段的中间对区域进行潜水来完成的.

示例:来源:

  vertices = [0 1;2 3;4 1;4 5];面孔= [1 2 3;2 3 4];数据= [1 2]; 

啮合后预期结果:

  vertices = [0 1;2 3;4 1;4 5;1 2;3 2;2 1;3 4;4 3];面孔= [1 5 7;2 5 6;5 6 7;7 6 3;2 6 8;6 8 9;6 9 3;8 4 9];数据= [1 1 1 1 2 2 2 2]; 

我正在使用:

  FV.Vertices =顶点;FV.Faces =面孔;FV.FaceVertexCData =数据;数字;坚持,稍等;轴相等并网补丁(FV,'FaceColor','flat'); 

精度:我不想使用下面的函数,这些函数会导致过多的顶点和面:

  • 您可以重复操作:

    I need to find a way to mesh triangles then to refine using refine. My vertices of my original triangles are stored inside a matrix of size nb_points * 2. My faces are stored in a nb_faces * 3 matrix. The data for each face is stored in a nb_face * 1 matrix. The meshing is done by diving the area using the middles of the segments of the triangles.

    Example : Origin :

    vertices = [0 1 ; 
                2 3 ; 
                4 1 ;
                4 5];
    faces = [1 2 3;
             2 3 4];
    data = [1 2]; 
    

    Result expected after meshing :

    vertices = [0 1; 
                2 3; 
                4 1;
                4 5;
                1 2;
                3 2;
                2 1;
                3 4;
                4 3];
    faces = [1 5 7;
             2 5 6;
             5 6 7;
             7 6 3;
             2 6 8;
             6 8 9;
             6 9 3;
             8 4 9];
    data = [1 1 1 1 2 2 2 2];
    

    I am displaying using :

    FV.Vertices = vertices; 
    FV.Faces = faces; 
    FV.FaceVertexCData = data;
    figure; hold on; axis equal; grid on;
    patch(FV,'FaceColor','flat');
    

    Precision : I do not want to use the following functions which gives way too many vertices and faces :

    The data are temperatures since this is a simulation of heat transfer.

    解决方案

    With a for loop it can be done quite easily, here is one solution:

    % Dummy data
    vertices = [0 1 ; 
                2 3 ; 
                4 1 ;
                4 5];
    faces = [1 2 3;
             2 3 4];
    data = [1 2]; 
    
    % Number of vertices
    vnum = size(vertices,1);
    
    % new faces empty vector
    nfaces = [];
    
    % triangular shift
    tshift = [2,-1,-1].';
    
    % Run the algorithm
    for ii = 1:size(faces,1)
        % For each triangle get the 3 pairs of vertices
        nsk = [faces(ii,1), faces(ii,2);faces(ii,2), faces(ii,3);faces(ii,3), faces(ii,1)];
        % Compute the center of each pair of vertices
        cmiddle = (vertices(nsk(:,1),:)+vertices(nsk(:,2),:))/2
        % Compute the new faces
        nfaces = [nfaces;[nsk(:,1),vnum+(ii*3-3+[1:3].'),vnum+(ii*3-3+[1:3].')+tshift];[(vnum+(ii*3-2)):(vnum+(ii*3))]]
        % Add the new vertices
        vertices = [vertices;cmiddle];
    end
    
    % Delete the duplicate vertices
    [vertices,~,ind] = unique(vertices,'rows');
    faces = ind(nfaces);
    
    % Plot
    figure; hold on; axis equal; grid on;
    patch('Faces',faces,'Vertices',vertices,'FaceVertexCData',kron(data,ones(1,4)).','FaceColor','flat')
    colorbar
    

    If you find a way to generate the nsk vector without for loop you could even get rid of the loop. This code will only work on triangle, but it can be adapted if needed.

    Result:

    You can repeat the operation:

    这篇关于生成网格并细化三角形的网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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