image thumbnail

rectangle2

version 2.0.0 (595 KB) by Adam Danz
Similar to Matlab's rectangle() but with more options.

44 Downloads

Updated 11 Jan 2021

View License

Similar to Matlab's rectangle() function but with these additional features:
* Position rectangles by their center points rather than by their lower left coordinate.
* Supports creation of multiple rectangles with independent properties
* Outputs handles to patch object rather than rectangle
* Outputs rectangles parameters including vertices
* Option to rotate rectangles about their centers

RECTANGLE2(POS) creates rectangles in 2D coordinates. POS is an nx4
matrix [x y w h] specifying the center (x,y), width (w) and height
(h) of n rectangles in data units on the current axes.

RECTANGLE2(CNT, WH) specifies the center, CNT, as an nx2 matrix of
[x,y] coordinates and the size, WH, as an nx2 matrix of widths and
heights. When either CNT or WH is 1x2 and the other is nx2 (n>1),
the 1x2 parameter is replicated for all rectangles.

RECTANGLE2(__,'Curvature',cur) adds curvature to the sides of the
rectangle. Different curvatures along the horizontal and vertical
edges is specified by an nx2 vector for n rectangles. The same length
of curvature will be applied to all sides when cur is a scalar.
Curvature is expressed by values between 0 (no curvature) and 1
(circular/elliptical). If only one row of values is supplied, the
same curvature will be applied to all rectangles.

RECTANGLE2(__,'Rotation',deg) defines the rotation of the rectangle
about its center in degrees. Negative values rotate clockwise. If
only one value is supplied, the same rotation will be applied to
all rectangles.

RECTANGLE2(__,Name,Value) specifies rectangle properties using one
or more Name,Value pair arguments accepted by Matlab's rectangle
function. FaceColor and EdgeColor can be specified for n rectangles
by specifying an nx1 cell of character vectors or an nx3 matrix of
rgb values. LineStyle can also be an nx1 cell of characters. LineWidth
can be an nx1 vector of values for n rectangles.

Postion (POS | CNT & WH) inputs and, if specified, curvature, rotation,
FaceColor, EdgeColor, LineWidth, and LineStyle must either have the same
number of rows or one row to be used for all rectangles.

RECTANGLE2(ax,__) specifies the axes.

[h, rect] = RECTANGLE2(__) returns an nx1 vector of patch handles, h,
for n rectangles and a structure, rect, containing data about the
rectangles.

Cite As

Adam Danz (2021). rectangle2 (https://www.mathworks.com/matlabcentral/fileexchange/85418-rectangle2), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: rectangles

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!