www.gusucode.com > graphics 案例源码程序 matlab代码 > graphics/UseComputedSurfaceNormalsForLightingExample.m

    %% Use Computed Surface Normals for Lighting
% Compute the normal vectors of an expression representing a surface.

% Copyright 2015 The MathWorks, Inc.


%%
[nx, ny, nz] = surfnorm(peaks);

%%
% Assign these normals to the |VertexNormals| property which MATLAB(R) uses
% to calculate the surface lighting. Set the lighting algorithm to
% |gouraud| and add a light using |camlight|.

b = reshape([nx ny nz], 49,49,3);
figure
surf(ones(49),'VertexNormals',b,'EdgeColor','none');
lighting gouraud
camlight

%%