isonormals

Computes surface normals of an isosurface from the gradient of the volume data.

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

Syntax

n = isonormals(X, Y, Z, V, verts)

Returns the normals at the vertices verts using the gradient of V.

n = isonormals(V, verts)

Uses the grid 1:n in each direction.

isonormals(___, p)

Sets the vertex normals of the patch p.

Description

Lighting a surface needs normals. The normals computed from the data gradient are smoother and more faithful than those derived from the triangles, so a lit isosurface looks round instead of faceted.

Input arguments

X, Y, Z, V
Grid and scalar volume data.
verts
n-by-3 matrix of vertices.

Output arguments

n
n-by-3 matrix of unit normal vectors, one per vertex.

Example

Normals of a sphere

[x, y, z] = meshgrid(-1:0.5:1);
v = x.^2 + y.^2 + z.^2;
fv = isosurface(x, y, z, v, 0.5);
n = isonormals(x, y, z, v, fv.vertices);
size(n)
norm(n(1,:))
Output
ans = 1×2

    74     3
ans = 1.1358

See also

isosurface isocaps isocolors patch lighting