surfnorm

Computes the normal vectors of a surface.

Category: Graphics > 2-D and 3-D Plots

Syntax

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

Returns normals of the surface with heights Z.

[Nx, Ny, Nz] = surfnorm(X, Y, Z)

Uses X and Y as coordinates.

surfnorm(___)

With no outputs, draws the surface with its normals as lines.

Description

The normal at each grid point is estimated from the neighboring points, and every vector has length 1. The normals are the basis of lighting calculations.

Input arguments

X, Y, Z
Matrices of the same size describing the surface.

Output arguments

Nx, Ny, Nz
Components of the unit normals, the same size as Z.

Example

Normal of a tilted plane

[X, Y] = meshgrid(-1:1);
Z = X + Y;
[Nx, Ny, Nz] = surfnorm(X, Y, Z);
disp([Nx(2,2) Ny(2,2) Nz(2,2)])
Output
   -0.5774   -0.5774    0.5774

See also

surf isonormals surfl quiver3