polyshape
Creates a 2-D polygon, possibly with several regions and holes, that supports geometry queries and Boolean operations.
Category: Mathematics > Computational Geometry
Syntax
pshape = polyshape(x, y)
Polygon from vertex coordinate vectors. NaN separates several boundaries.
pshape = polyshape(P)
Vertices as the rows of a two-column matrix.
pshape = polyshape(___, 'Simplify', tf)
Turns off the automatic repair of the input when tf is false.
pshape = polyshape()
An empty polyshape.
Description
A polyshape represents a planar region bounded by polygons. A boundary inside another becomes a hole, and boundaries that do not touch become separate regions. Geometry is available through functions such as area, perimeter, centroid, isinterior, holes, regions, rotate, scale and translate, and through the Boolean operations union, intersect, subtract and xor.
When the input has defects, such as a bowtie-shaped boundary that crosses itself, the constructor repairs it and splits it into valid pieces. A degenerate input, such as three collinear points, gives an empty polyshape with NumRegions equal to 0.
Input arguments
x, y- Vectors of the same length with the vertex coordinates, in order around the boundary.
'Simplify'- Logical. By default (
true) the constructor fixes self-intersections, duplicate vertices and orientation, and prints a warning if it had to.
Output arguments
pshape- A
polyshapewith read-only propertiesVertices(the list of vertices, boundaries separated byNaNrows),NumRegionsandNumHoles.
Example
Two regions in one polyshape
P = polyshape([0 1 1 0 NaN 3 5 5 3], [0 0 1 1 NaN 0 0 2 2]);
P.NumRegions
area(P)
centroid(P)
ans = 2
ans = 5
ans = 1×2
3.3000 0.9000