%% Surface of a Cube
% Compute and plot the unit normal vectors to the vertices of a triangulation.
% Create a 3-D triangulation representing the volume of a cube.

[X,Y,Z] = meshgrid(1:4);
x = X(:);
y = Y(:);
z = Z(:);
DT = delaunayTriangulation(x,y,z);

%
% Triangulate the boundary of the cube.

[Tfb,Xfb] = freeBoundary(DT);
TR = triangulation(Tfb,Xfb);

%
% Find the unit normal vectors to the triangle vertices.

V = vertexNormal(TR);

%
% Plot the triangulated surface and the unit normal vectors.

trisurf(TR,'FaceColor',[0.8 0.8 1.0]);
axis equal
hold on
quiver3(Xfb(:,1),Xfb(:,2),Xfb(:,3), ...
     V(:,1),V(:,2),V(:,3),0.5,'Color','b');

% Copyright 2015 The MathWorks, Inc.