%% Plot Tetrahedra That Construct a Cube
% Create 8 points that represent the corners of a cube in Cartesian coordinates.

d = [-1 1];
[x,y,z] = meshgrid(d);
X = [x(:) y(:) z(:)]

% Specify a tetrahedron connectivity matrix where each row contains the indices into X that specify the 4 vertices of a tetrahedron. For instance, the first row describes a tetrahedron with vertices consisting of the first, third, fourth, and seventh points.

T = [1 3 4 7;
     4 6 7 8;
     1 5 6 7;
     1 2 4 6;
     1 4 6 7]

% Use tetramesh to plot the 5 tetrahedra that form the cube.

tetramesh(T,X);
view(-40,20)

%
% To see into the cube, plot it again with more transparent faces.

tetramesh(T,X,'FaceAlpha',0.1);
view(-40,20)

%
% Copyright 2020 The MathWorks, Inc.