www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/PlotUnitNormalstoFacetsonaSphericalSurfaceExample.m
%% Plot Unit Normals to Facets on a Spherical Surface %% % Create a set of random points on a spherical surface. theta = gallery('uniformdata',[100,1],0)*2*pi; phi = gallery('uniformdata',[100,1],1)*pi; x = cos(theta).*sin(phi); y = sin(theta).*sin(phi); z = cos(phi); %% % Triangulate the points with |delaunayTriangulation|. DT = delaunayTriangulation(x,y,z); %% % Find the free boundary facets and use them to create a triangulation representation % for plotting. [T,Xb] = freeBoundary(DT); TR = triangulation(T,Xb); %% % Plot the triangulation. figure trisurf(T,Xb(:,1),Xb(:,2),Xb(:,3), ... 'FaceColor', 'cyan', 'faceAlpha', 0.8); axis equal; hold on; % Calculate the incenters and face normals. P = incenter(TR); fn = faceNormal(TR); % Display the normal vectors on the surface. quiver3(P(:,1),P(:,2),P(:,3), ... fn(:,1),fn(:,2),fn(:,3),0.5, 'color','r'); hold off;