www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/UnitNormalVectorstotheSurfaceofaCubeExample.m
%% Unit Normal Vectors to the Surface of a Cube % Copyright 2015 The MathWorks, Inc. %% % 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); %% % Find the surfaces of the cube and isolate them in a 2-D triangulation. [Tfb,Xfb] = freeBoundary(dt); TR = triangulation(Tfb,Xfb); %% % Find the unit normal vectors to the triangles on the surface of the cube. vn = vertexNormal(TR); %% % Plot the results. trisurf(TR,'FaceColor', [0.8 0.8 1.0]); axis equal hold on quiver3(Xfb(:,1),Xfb(:,2),Xfb(:,3),... vn(:,1),vn(:,2),vn(:,3),0.5,'color','b'); hold off