Skip to content

drawPolygon

David Legland edited this page Feb 28, 2022 · 1 revision

Draw a polygon specified by a list of points.

Usage

drawPolygon(POLY);

Packs coordinates in a single N-by-2 array, with N the vertex number.

drawPolygon(PX, PY);

Specifies coordinates in separate arrays. Both array must be N-by-1, with N the number of vertices.

drawPolygon(POLYS)

Packs coordinate of several polygons in a cell array. Each element of the array is a Ni-by-2 double array.

drawPolygon(..., NAME, VALUE);

Specifies drawing options by using one or several parameter name-value pairs, see the doc of plot function for details.

drawPolygon(AX, ...)

Specifies the axis to draw the polygon on.

H = drawPolygon(...);

Also return a handle to the list of line objects.

Examples

Draw a red rectangle

poly = [10 10;40 10;40 30;10 30];
figure; drawPolygon(poly, 'r');
axis equal; axis([0 50 0 50]); 

Draw two squares

px = [10 20 20 10 NaN 30 40 40 30]';
py = [10 10 20 20 NaN 10 10 20 20]';
figure; 
drawPolygon([px py], 'lineWidth', 2);
axis equal; axis([0 50 0 50]); 

See also

polygons2d, drawPolyline

Clone this wiki locally