Navigation

Operators and Keywords

Function List:

C++ API

: shrinkfaces (p, sf)
: nfv = shrinkfaces (p, sf)
: nfv = shrinkfaces (fv, sf)
: nfv = shrinkfaces (f, v, sf)
: [nf, nv] = shrinkfaces (…)

Reduce the size of faces in a patch by the shrink factor sf.

The patch object can be specified by a graphics handle (p), a patch structure (fv) with the fields "faces" and "vertices", or as two separate matrices (f, v) of faces and vertices.

The shrink factor sf is a positive number specifying the percentage of the original area the new face will occupy. If no factor is given the default is 0.3 (a reduction to 30% of the original size). A factor greater than 1.0 will result in the expansion of faces.

Given a patch handle as the first input argument and no output parameters, perform the shrinking of the patch faces in place and redraw the patch.

If called with one output argument, return a structure with fields "faces", "vertices", and "facevertexcdata" containing the data after shrinking. This structure can be used directly as an input argument to the patch function.

Caution:: Performing the shrink operation on faces which are not convex can lead to undesirable results.

Example: a triangulated 3/4 circle and the corresponding shrunken version.

[phi r] = meshgrid (linspace (0, 1.5*pi, 16), linspace (1, 2, 4));
tri = delaunay (phi(:), r(:));
v = [r(:).*sin(phi(:)) r(:).*cos(phi(:))];
clf ()
p = patch ("Faces", tri, "Vertices", v, "FaceColor", "none");
fv = shrinkfaces (p);
patch (fv)
axis equal
grid on

See also: patch.

Demonstration 1

The following code

 clf;
 faces = [1 2 3; 1 3 4];
 vertices = [0 0; 1 0; 1 1; 0 1];
 patch ("Faces", faces, "Vertices", vertices, "FaceColor", "none");
 fv = shrinkfaces (faces, vertices, 0.25);
 patch (fv);
 axis auto;   # Kludge required for Octave
 axis equal;

Produces the following figure

Figure 1

Demonstration 2

The following code

 clf;
 faces = [1 2 3 4; 5 6 7 8];
 vertices = [0 0; 1 0; 2 1; 1 1; 2 0; 3 0; 4 1; 3.5 1];
 patch ("Faces", faces, "Vertices", vertices, "FaceColor", "none");
 fv = shrinkfaces (faces, vertices, 0.25);
 patch (fv);
 axis auto;   # Kludge required for Octave
 axis equal;
 grid on;

Produces the following figure

Figure 1

Demonstration 3

The following code

 clf;
 faces = [1 2 3 4];
 vertices = [-1 2; 0 0; 1 2; 0 1];
 patch ("Faces", faces, "Vertices", vertices, "FaceColor", "none");
 fv = shrinkfaces (faces, vertices, 0.25);
 patch (fv);
 axis auto;   # Kludge required for Octave
 axis equal;
 grid on;
 title "faces which are not convex are clearly not allowed"

Produces the following figure

Figure 1

Demonstration 4

The following code

 clf;
 [phi r] = meshgrid (linspace (0, 1.5*pi, 16), linspace (1, 2, 4));
 tri = delaunay (phi(:), r(:));
 v = [r(:).*sin(phi(:)) r(:).*cos(phi(:))];
 p = patch ("Faces", tri, "Vertices", v, "FaceColor", "none");
 fv = shrinkfaces (p);
 patch (fv);
 axis auto;   # Kludge required for Octave
 axis equal;
 grid on;

Produces the following figure

Figure 1

Demonstration 5

The following code

 clf;
 N = 10;  % N intervals per axis
 [x, y, z] = meshgrid (linspace (-4,4,N+1));
 val = x.^3 + y.^3 + z.^3;
 fv = isosurface (x, y, z, val, 3, z, "noshare");

 p = patch ("Faces", fv.faces, "Vertices", fv.vertices, "FaceVertexCData", ...
            fv.facevertexcdata, "FaceColor", "interp", "EdgeColor", "black");
 axis auto;   # Kludge required for Octave
 axis equal;
 view (115, 30);
 drawnow;
 shrinkfaces (p, 0.6);

Produces the following figure

Figure 1

Package: octave