# surfnorm

## Purpose

Compute and display 3-D surface normals.

## Synopsis

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

## Description

`[Nx,Ny,Nz] = surfnorm(X,Y,Z)` returns the components of the three-dimensional surface normals for the surface defined by the matrices `X`, `Y`, and `Z`. The surface normals are unnormalized and are valid at each vertex.`surfnorm` is used by `surfl` to compute surface normals.

`[Nx,Ny,Nz] = surfnorm(Z)` returns the normal vector components for the surface defined by `Z`.

`surfnorm(Z)` and `surfnorm(X,Y,Z)` plot the surface with the normals emanating from it. Normals are not shown for surface elements that face away from the viewer.

The direction of the normals is reversed by calling `surfnorm` with transposed arguments.

    surfnorm(X',Y',Z')

## Algorithm

The surface normals are based on a bicubic fit of the data in the `X`, `Y`, and `Z` matrices. For each vertex, diagonal vectors are computed and crossed to form the normal.

## Examples

Plot the normal vectors for a truncated cone.

    [x,y,z] = cylinder(1:10);

    surfnorm(x,y,z)

## ``See Also

    diffuse, specular, surfl

(c) Copyright 1994 by The MathWorks, Inc.