4

我想在 MATLAB 中绘制四面体。我怎样才能做到这一点?

一只忙碌的猫

4

2 回答 2

4

Try this

X = [x1 x2 x3 x4]';
Y = [y1 y2 y3 y4]';
Z = [z1 z2 z3 z4]';    
T = [1 2 3; 1 2 4; 2 3 4; 1 3 4];    
trimesh(T,X,Y,Z);

and see if it works. The values x1 y1 and z1 are the respective x y x coordinate of vertex 1 (similarly for the other vertices). I dont have MATLAB access right now so I have modified this from my octagon generator code. You might need to play with the vertices order to get it to work, but this approach will enable you to plot your tetrahedron

Edit: another option is trisurf in place of trimesh to get surface rather than wireframe

于 2012-07-06T08:50:53.237 回答
0
    % Draws tetrahedron inscribed in sphere of radius 1
    function draw_regular_tetrahedron(T)

        T = 1/hypot(1, sqrt(2)/2)*T; % scale to fit in unit sphere

        z = 1/sqrt(2);
        S.Vertices = (T*[1,0,-z;-1,0,-z;0,1,z;0,-1,z]')';
        S.Faces = [1,3,4;2,3,4;1,2,3;1,2,4];
        S.FaceVertexCData = [ 1 ];
        S.FaceColor = 'flat';
        S.EdgeColor = 'green';
        p = patch(S);
        alpha(p, 0.5);
    end

>> ps_5_2.draw_regular_tetrahedron(eye(3))
>> ps_5_2.draw_regular_tetrahedron(eye(3)*5)

在此处输入图像描述

于 2017-06-25T04:18:08.930 回答