Navigation

Operators and Keywords

Function List:

C++ API

: surfnorm (x, y, z)
: surfnorm (z)
: surfnorm (…, prop, val, …)
: surfnorm (hax, …)
: [nx, ny, nz] = surfnorm (…)

Find the vectors normal to a meshgridded surface.

If x and y are vectors, then a typical vertex is (x(j), y(i), z(i,j)). Thus, columns of z correspond to different x values and rows of z correspond to different y values. If only a single input z is given then x is taken to be 1:rows (z) and y is 1:columns (z).

If no return arguments are requested, a surface plot with the normal vectors to the surface is plotted.

Any property/value input pairs are assigned to the surface object.

If the first argument hax is an axes handle, then plot into this axis, rather than the current axes returned by gca.

If output arguments are requested then the components of the normal vectors are returned in nx, ny, and nz and no plot is made. The normal vectors are unnormalized (magnitude != 1). To normalize, use

mag = sqrt (nx.^2 + ny.^2 + nz.^2);
nx ./= len;  ny ./= len;  nz ./= len;

An example of the use of surfnorm is

surfnorm (peaks (25));

Algorithm: The normal vectors are calculated by taking the cross product of the diagonals of each of the quadrilateral faces in the meshgrid to find the normal vectors at the center of each face. Next, for each meshgrid point the four nearest normal vectors are averaged to obtain the final normal to the surface at the meshgrid point.

For surface objects, the "VertexNormals" property contains equivalent information, except possibly near the boundary of the surface where different interpolation schemes may yield slightly different values.

See also: isonormals, quiver3, surf, meshgrid.

Demonstration 1

The following code

 clf;
 colormap ("default");
 surfnorm (peaks (19));
 shading faceted;
 title ({"surfnorm() shows surface and normals at each vertex", ...
         "peaks() function with 19 faces"});

Produces the following figure

Figure 1

Demonstration 2

The following code

 clf;
 colormap ("default");
 [x, y, z] = sombrero (10);
 surfnorm (x, y, z);
 title ({"surfnorm() shows surface and normals at each vertex", ...
         "sombrero() function with 10 faces"});

Produces the following figure

Figure 1

Package: octave