The polygons2d module contains functions operating on shapes composed of a vertex list, like polygons or polylines.
We call polyline the curve defined by a series of vertices. A polyline can be either closed or open, depending on whether the last vertex is connected to the first one or not. This can be given as an option is some functions in the module.
A polygon is the planar domain delimited by a closed polyline. We sometimes want to consider 'complex polygons', whose boundary is composed of several disjoint domains. The domain defined by a single closed polyline is called simple polygon.
We call curve a polyline with many vertices, such that the polyline can be considered as a discrete approximation of a "real" curve.
A simple polygon or polyline is represented by a N-by-2 array, each row of the array representing the coordinates of a vertex. Simple polygons are assumed to be closed, so there is no need to repeat the first vertex at the end. As both polygons and polylines can be represented by a list of vertex coordinates, some functions also consider the vertex list itself. Such functions are prefixed by 'pointSet'. Also, many functions prefixed by polygon or polyline works also on the other type of shape.
For multiple-connected polygons, the different connected boundaries are separated by a row [NaN NaN].
For some functions, the orientation of the polygon can be relevant: CCW stands for 'Conter-Clockwise' (positive orientation), CW stands for 'Clockwise'.
Polylines are parametrized in the following way:
- the i-th vertex is located at position i-1
- points of the i-th edge have positions ranging linearly from i-1 to i
The parametrization domain for an open polyline is from 0 to Nv-1, and from 0 to Nv for a closed polyline (positions 0 and Nv correspond to the same point).
A simple working example to display polygons:
% Simple polygon: P1 = [1 1;2 1;2 2;1 2]; drawPolygon(P1); axis([0 5 0 5]); % Multiple polygon: P2 = [10 10;40 10;40 40;10 40;NaN NaN;20 20;20 30;30 30;30 20]; figure;drawPolygon(P2); axis([0 50 0 50]);