【问题标题】:Matlab drawing tetrahedrons and trianglesMatlab绘制四面体和三角形
【发布时间】:2012-06-18 22:55:16
【问题描述】:

我在 MATLAB 中实现 Crust 算法,绘制结果图时遇到问题。

我在三维空间中有一个 pointsArray (1000x3) 点数组。

  1. 我有一个矩阵 M (100x4)。每行是一个向量,包含 4 个 pointsArray 索引,构成一个四面体。现在我想以某种有效的方式绘制所有这些四面体。

    目前我正在使用“for”循环和补丁(FV)方法,但是对于几千个四面体,它正在扼杀我的 CPU。

  2. 我有一个矩阵 N (100x3)。每行是一个向量,包含 3 个 pointsArray 索引,在三维空间中形成一个三角形。我也想画这些三角形。

任何想法,如何以某种有效的方式绘制这些数字?

编辑:问题已解决。我用的是 trisurf 而不是补丁。

【问题讨论】:

    标签: matlab graphics 3d rendering matlab-figure


    【解决方案1】:

    关于第二个问题(三角面),我使用以下代码:

    %% Wire plot
    % The idea is to plot all triangles as one line. But to make part of the
    % line connecting two triangles invisible, add NaN after each 3 points of
    % triangle.
    
    NTri = size(N,1);
    X = reshape(pointsArray(N.',1), 3, NTri);   X = reshape([X; nan(1,NTri)], 4*NTri, 1);
    Y = reshape(pointsArray(N.',2), 3, NTri);   Y = reshape([Y; nan(1,NTri)], 4*NTri, 1);
    Z = reshape(pointsArray(N.',3), 3, NTri);   Z = reshape([Z; nan(1,NTri)], 4*NTri, 1);
    figure;
    plot3(X,Y,Z,'-k.');
    axis equal
    
    %% Surface plot
    % patch also can plot all triangles at once. I use the following code to
    % plot triangulated objects consisting of more than 300000 triangles and it
    % is very fast.
    
    px = [pointsArray(N(:,1),1) pointsArray(N(:,2),1) pointsArray(N(:,3),1)].';
    py = [pointsArray(N(:,1),2) pointsArray(N(:,2),2) pointsArray(N(:,3),2)].';
    pz = [pointsArray(N(:,1),3) pointsArray(N(:,2),3) pointsArray(N(:,3),3)].';
    figure
    patch(px,py,pz, 'g');
    axis equal
    

    希望对某人有所帮助。

    // 奥列格

    【讨论】:

      【解决方案2】:

      尝试将figure render property改为opengl

         set(gcf,'Render','OpenGL');
      

      但它仅适用于 3D 中的三角形。四面体可以表示为2个三角形。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-07-12
        • 2018-04-26
        • 2014-12-10
        • 2014-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多