POLYSHAPE Create polyshape object
A polyshape is a 2-D polygon that can consist of one or more solid regions,
and can have holes. polyshape objects are created from the x- and
y-coordinates that describe the polygon's boundaries.
Boundaries that make up a polyshape should have no self-intersections or
intersections with other boundaries, and all boundaries should be properly
nested. Otherwise, the polyshape is ill-defined, and can lead to inaccurate
or unexpected results.
PG = POLYSHAPE(X, Y) creates a polyshape object from 2-D vertices given
by two vectors X and Y. X and Y must have the same size.
PG = POLYSHAPE(P) creates a polyshape from 2-D points contained in the
2-column array P.
PG = POLYSHAPE({X1, X2, ..., Xn}, {Y1, Y2, ..., Yn}) creates a polyshape
with n boundaries from two cell arrays. Each cell array contains n vectors,
where each Xi contains the x-coordinates and Yi contains the y-coordinates
of the i-th boundary.
PG = POLYSHAPE(..., 'SolidBoundaryOrientation', DIR) specifies the
direction convention for determining solid versus hole boundaries. DIR
can be one of the following:
'auto' (default) - Automatically determine direction convention
'cw' - Clockwise vertex direction defines solid boundaries
'ccw' - Counterclockwise vertex direction defines solid boundaries
This name-value pair is typically only specified when creating a polyshape
from data that was produced by other software that uses a particular
convention.
PG = POLYSHAPE(..., 'Simplify', tf) specifies how ill-defined polyshape
boundaries are handled. tf can be one of the following:
true (default) - Automatically alter boundary vertices to create a
well-defined polygon
false - Do not alter boundary vertices even though the polyshape is
ill-defined. This may lead to inaccurate or unexpected results.
PG = POLYSHAPE(..., 'KeepCollinearPoints', tf) specifies how to treat
consecutive vertices lying along a straight line. tf can be one of the
following:
true - Keep all collinear points as vertices of PG.
false - Remove collinear points so that PG contains the fewest number
of necessary vertices.
The value of the 'KeepCollinearPoints' parameter is carried over when the
ADDBOUNDARY, INTERSECT, SIMPLIFY, SUBTRACT, UNION, and XOR functions are
used with input PG.
PG = POLYSHAPE() creates a polyshape object with no vertices.
Polyshape properties:
Vertices - 2-D polyshape vertices
NumRegions - Number of regions in the polyshape
NumHoles - Number of holes in the polyshape
Methods for modifying a polyshape:
addboundary - Add boundaries to a polyshape
rmboundary - Remove boundaries in a polyshape
rmholes - Remove all the holes in a polyshape
rmslivers - Clean up degeneracies in a polyshape
simplify - Fix degeneracies and intersections in a polyshape
Methods for querying a polyshape:
ishole - Determine if a boundary is a hole
issimplified - Determine if a polyshape is simplified
numsides - Find the total number of sides in a polyshape
numboundaries - Find the total number of boundaries in a polyshape
Methods for geometric information:
area - Find the area of a polyshape
boundary - Get the x- and y-coordinates of a boundary
boundingbox - Find the bounding box of a polyshape
centroid - Find the centroid of a polyshape
convhull - Find the convex hull of a polyshape
holes - Convert all holes in a polyshape into an array of polyshapes
isinterior - Determine if a point is inside a polyshape
nearestvertex - Find the vertex of a polyshape nearest to a point
overlaps - Determine if two polyshapes overlap
perimeter - Get the perimeter of a polyshape
regions - Put all regions in a polyshape into an array of polyshapes
triangulation - Construct a 2-D triangulation from polyshape
Methods for transformation:
rotate - Rotate a polyshape by angle with respect to a center
scale - Scale a polyshape by a factor
translate - Translate a polyshape by a vector
Methods for Boolean operations:
intersect - Find the intersection of two polyshapes or between polyshape and line
subtract - Find the difference of two polyshapes
union - Find the union of two polyshapes
xor - Find the exclusive or of two polyshapes
Other methods:
polybuffer - Create buffer zone around polyshape
isequal - Determine if two polyshapes are identical
plot - Plot polyshape and return a Polygon object handle
sortboundaries - Sort boundaries in polyshape
sortregions - Sort regions in polyshape
turningdist - Find the turning distance of two polyshapes
Example: Find the area and centroid of a polyshape and plot it
%create a polyshape with 4 vertices
quadShp = polyshape([0 0 1 3], [0 3 3 0]);
%compute area and centroid
a = area(quadShp);
[cx, cy] = centroid(quadShp);
figure; plot(quadShp);
hold on
%plot centroid point as '*'
plot(cx, cy, '*');
See also area, centroid, nsidedpoly
Documentation for polyshape
doc polyshape