Navigation

Operators and Keywords

Function List:

C++ API

Function File: surfnorm (x, y, z)
Function File: surfnorm (z)
Function File: surfnorm (…, prop, val, …)
Function File: surfnorm (hax, …)
Function File: [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.

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 quadrilaterals in the meshgrid to find the normal vectors of the centers of these quadrilaterals. The four nearest normal vectors to the meshgrid points are then averaged to obtain the normal to the surface at the meshgridded points.

See also: isonormals, quiver3, surf, meshgrid.

Demonstration 1

The following code

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

Produces the following figure

Figure 1

Demonstration 2

The following code

 clf;
 colormap ('default');
 [x, y, z] = sombrero (10);
 surfnorm (x, y, z);

Produces the following figure

Figure 1

Package: octave