Documentation Center

  • Trial Software
  • Product Updates

poly2fv

Convert polygonal region to patch faces and vertices

Syntax

[F,V] = poly2fv(x,y)

Description

[F,V] = poly2fv(x,y) converts the polygonal region represented by the contours (x,y) into a faces matrix, F, and a vertices matrix, V, that can be used with the patch function to display the region. If the polygon represented by x and y has multiple parts, either the NaN-separated vector format or the cell array format may be used. The poly2fv function creates triangular faces.

Most Mapping Toolbox™ functions adhere to the convention that individual contours with clockwise-ordered vertices are external contours and individual contours with counterclockwise-ordered vertices are internal contours. Although the poly2fv function ignores vertex order, you should follow the convention when creating contours to ensure consistency with other functions.

Examples

Display a rectangular region with two holes using a single patch object.

% External contour, rectangle.
x1 = [0 0 6 6 0];
y1 = [0 3 3 0 0];

% First hole contour, square.
x2 = [1 2 2 1 1];
y2 = [1 1 2 2 1];

% Second hole contour, triangle.
x3 = [4 5 4 4];
y3 = [1 1 2 1];

% Compute face and vertex matrices.
[f, v] = poly2fv({x1, x2, x3}, {y1, y2, y3});

% Display the patch.
patch('Faces', f, 'Vertices', v, 'FaceColor', 'r', ...
 'EdgeColor', 'none');
axis off, axis equal

See the documentation for the function polybool for additional examples illustrating poly2fv.

Was this topic helpful?