Quantcast

Documentation Center

  • Trial Software
  • Product Updates

surfnorm

Compute and display 3-D surface normals

Syntax

surfnorm(Z)
surfnorm(X,Y,Z)
surfnorm(axes_handle,___)
surfnorm(___,Name,Value)
[Nx,Ny,Nz] = surfnorm(___)

Description

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 Surface 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

Z

2–D array of real numbers representing a surface

X

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

Y

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

axes_handle

Handle to the target axes in which to plot the surface

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

Name,Value

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 Surface Properties for description of property names and values.

Output Arguments

[Nx,Ny,Nz]

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

Examples

expand all

Display 3-D Surface Normals for Cone Plot

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

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

Use Computed Surface Normals for Lighting

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);
figure
surf(ones(49),'VertexNormals',b,'EdgeColor','none');
lighting gouraud
camlight

More About

expand 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

Tips

  • surfnorm does not accept complex inputs.

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

    surfnorm(X',Y',Z')
    
  • 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.

Algorithms

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.

See Also

| | | |

Was this topic helpful?