【问题标题】:Generate mesh and refine mesh of triangles生成网格并细化三角形网格
【发布时间】:2019-12-19 01:39:39
【问题描述】:

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

示例: 产地:

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

网格化后的预期结果:

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];

我正在使用:

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

精度: 我不想使用以下会提供太多顶点和面的函数:

数据是温度,因为这是对热传递的模拟。

【问题讨论】:

    标签: matlab math matrix physics-engine


    【解决方案1】:

    使用 for 循环可以很容易地完成,这里有一个解决方案:

    % 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
    

    如果您找到一种无需 for 循环即可生成 nsk 向量的方法,您甚至可以摆脱循环。此代码仅适用于三角形,但可以根据需要进行调整。

    结果:

    你可以重复操作:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-25
      • 2022-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-27
      • 2017-01-15
      • 1970-01-01
      相关资源
      最近更新 更多