This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Compute and display 3-D surface normals


[Nx,Ny,Nz] = surfnorm(___)


surfnorm(Z) plots a surface of the matrix Z with surf and displays its surface normals as radiating vectors.

surfnorm(X,Y,Z) plots a surface and its surface normals from the vectors or matrices X, Y, and matrix Z. X, Y, and Z must be the same size.

surfnorm(axes_handle,___) plots into axes_handle instead of gca and it can include any of the input arguments in previous syntaxes.

surfnorm(___,Name,Value) can be used to set the value of the specified Chart Surface Properties properties.

[Nx,Ny,Nz] = surfnorm(___) returns the components of the 3-D surface normals for the surface without plotting the surface or surface normals.

Input Arguments


2–D array of real numbers representing a surface


2–D array of real numbers that defines the x component of the surface grid


2–D array of real numbers that defines the y component of the surface grid


Handle to the target axes in which to plot the surface

If you do not specify axes_handle, MATLAB® uses current axes.


Specify optional comma-separated pairs of Name,Value arguments, where Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Property names and values of the surface object

See Chart Surface Properties for description of property names and values.

Output Arguments


x, y, and z components of the three-dimensional surface normals for the surface


collapse all

Compute and plot the normal vectors for a truncated cone. Set the axis limits using the axis function.

[x,y,z] = cylinder(1:10);
axis([-12 12 -12 12 -0.1 1])

Compute the normal vectors of an expression representing a surface.

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

Assign these normals to the VertexNormals property which MATLAB® 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);
lighting gouraud

More About

collapse all

Surface Normal

An imaginary line perpendicular to a flat surface or perpendicular to the tangent plane at a point on a non-flat surface


  • surfnorm does not accept complex inputs.

  • Reverse the direction of the normals by calling surfnorm with transposed arguments:


  • The surface normals represent conditions at vertices and are not normalized. Normals for surface elements that face away from the viewer do not display.

  • surfl uses surfnorm to compute surface normals when calculating the reflectance of a surface.


After performing a bicubic fit of the data in the x, y, and z directions, diagonal vectors are computed and crossed to form the normal at each vertex.

Introduced before R2006a

Was this topic helpful?