rectangle

Contents

Syntax

davinci( 'rectangle', 'Position', [x y], 'Height', h, 'Width', w )
davinci( ___, 'CornerRadius', cr )
davinci( ___, 'DrawMethod', dm )
davinci( ___, 'NPointsInCurve', npts )
davinci( ___, 'Rotation', r )
davinci( ___, 'TagPoint', [xt yt] )
davinci( ___, <StyleParameterName>, styleparametervalue )
h = davinci( ___ )

Description

Draw a rectangle. Rounded or slanted corners are optional.

Parameter Default Comments
CornerRadius 0 The radius of curvature for the rounded corners of the rectangle, as illustrated in the figure above. When equal to zero, the rectangle is drawn with sharp corners (no rounding). See NPointsInCurve for more detail about the CornerRadius.
DrawMethod 'plot' Options are 'plot' and 'patch'. Indicates whether the rectangle should be drawn with the plot() command (which generates a line object) or with the patch() command (which generates a patch object).
Height Required The Height of the rectangle, as illustrated in the figure above. (Height does not have to be larger than Width.)
NPointsInCurve 30

The number of vertices used to help approximate the curve in each of the four corners of the rectangle, as illustrated in the figure below. Ignored unless CornerRadius is set to a non-zero value.

In the figure below are three rectangles with the same Width, Height, and CornerRadius as each other but different values for NPointsInCurve (0, 1, and 2 as indicated in the figure). Black dots mark the "center of curvature" of each corner. Red dots mark the vertices at the two ends of each of the four straight-line segments in the rectangle. Green dots mark the remaining vertices that help approximate a rounded corner. NPointsInCurve equals the number of vertices with green dots in each of the four corners of the rectangle. A larger value for NPointsInCurve results in a smoother curve. Each vertex (green and red) is a distance CornerRadius from the corresponding "center of curvature." The vertices that approximate a rounded corner are spaced uniformly in angle about the "center of curvature."

Also labeled in the figure below are vertex indices. Vertex #1 is at the top of the straight segment on the left side of the rectangle. The vertex indices increase clockwise around the rectangle. The three rectangles are drawn with Rotation equal to 0. When the rectangle is drawn as a patch object the max index is the index shown in the figure (e.g., 12 for the middle rectangle). When the rectangle is drawn as a line object, there is one extra vertex since the first vertex gets repeated at the end (e.g., 13 indices for the middle rectangle).

Position Required Position nominally corresponds to the point at the center of the rectangle. However this changes when the value of TagPoint is set to something other than [0 0].
Rotation 0 The rotation angle of the rectangle about the tag point. Units are degrees. A positive value rotates the rectangle counter-clockwise. In the figure at top, the rotation angle is 0.
TagPoint [0 0] A point in the xt-yt coordinate system. See the figure at top. The xt-yt coordinate origin is at the center of the rectangle. TagPoint is used for both of the following simultaneously:
  1. The value of TagPoint marks the point Position corresponds to. See an example in the figure at top.
  2. The value of TagPoint marks the point about which the rectangle gets rotated (see Rotation).
Width Required The Width of the rectangle, as illustrated in the figure at top.

Style Parameters

The table below lists the available style parameters.

Parameter Default Comments
Color 'k' The Color property of the Matlab line object (if the rectangle is drawn as a line object). Also the FaceColor property of the Matlab patch object (if the rectangle is drawn as a patch object), unless the FaceColor property is specified explicitly (see below).
EdgeColor 'none' The EdgeColor property of the Matlab patch object (if the rectangle is drawn as a patch object).
FaceAlpha 1 The FaceAlpha property of the Matlab patch object (if the rectangle is drawn as a patch object).
FaceColor See "Comments". The FaceColor property of the Matlab patch object (if the rectangle is drawn as a patch object). If the FaceColor parameter/value pair is not specified in the call to davinci(), the patch object's FaceColor property is set to the value of the Color parameter/value pair, which as shown above defaults to 'k'.
FaceVertexAlphaData[] The FaceVertexAlphaData property of the Matlab patch object (if the rectangle is drawn as a patch object).
FaceVertexCData [] The FaceVertexCData property of the Matlab patch object (if the rectangle is drawn as a patch object).
LineStyle '-' The LineStyle property of the Matlab line or patch object (whichever is created).
LineWidth 0.5 The LineWidth property of the Matlab line or patch object (whichever is created).

Tip

Examples

EXAMPLE #1 -- SIMPLE RECTANGLE.

davinci( 'rectangle', 'Position', [3 10], ...
                      'Height', 2, ...
                      'Width', 5, ...
                      'LineWidth', 2 );
daspect( [1 1 1] )   % Set the aspect ratio at 1:1.

EXAMPLE #2 -- RECTANGLE ROTATED ABOUT ITS CENTER.

davinci( 'rectangle', 'Position', [3 10], ...
                      'Height', 1, ...
                      'Width', 5, ...
                      'Rotation', 20, ...
                      'LineWidth', 2 );
daspect( [1 1 1] )

EXAMPLE #3 -- RECTANGLE POSITIONED AT, AND ROTATED ABOUT, A "TAG POINT."

Place the "tag point" on the lower-left corner of the rectangle (before rotation). Position the rectangle so this "tag point" is at coordinates [3 10]. Rotate the rectangle 20 degrees CCW about the "tag point."

h = 1;
w = 5;
davinci( 'rectangle', 'TagPoint', [-w/2 -h/2], ...
                      'Position', [3 10], ...
                      'Height', h, ...
                      'Width', w, ...
                      'Rotation', 20, ...
                      'LineWidth', 2 );
daspect( [1 1 1] )

EXAMPLE #4 -- ROUNDED CORNERS.

davinci( 'rectangle', 'Position', [3 10], ...
                      'Height', 4, ...
                      'Width', 6, ...
                      'CornerRadius', 1, ...
                      'LineWidth', 2 );
daspect( [1 1 1] )

EXAMPLE #5 -- SPECIAL CASES.

The code to draw these special cases is here.

EXAMPLE #6 -- ARTISTIC USE OF TRANSPARENCY.

% Make artistic use of Matlab's transparency ("alpha") settings for patch objects.
davinci( 'rectangle', 'Position',            [0 0], ...
                      'Width',               5, ...
                      'Height',              1, ...
                      'DrawMethod',          'patch', ...
                      'FaceVertexAlphaData', [ 0.6 0.7 0.6 0.7 ]', ... % Note the '.
                      'FaceAlpha',           'interp', ...
                      'EdgeColor',           'k', ...
                      'LineWidth',           2 );
daspect( [1 1 1] )

EXAMPLE #7 -- ARTISTIC USE OF INTERPOLATED FACE COLORS.

% Make artistic use of Matlab's interpolated face color settings for patch objects.
davinci( 'rectangle', 'Position',        [0 0], ...
                      'Width',           5, ...
                      'Height',          1, ...
                      'DrawMethod',      'patch', ...
                      'FaceVertexCData', [ [1 1 0];        % Vertex #1.  Yellow.
                                           [1 0 0];        % Vertex #2.  Red.
                                           [1 .7 0];       % Vertex #3.  Off-yellow.
                                           [1 0 0] ], ...  % Vertex #4.  Red.
                      'FaceColor',       'interp', ...
                      'EdgeColor',       'k', ...
                      'LineWidth',       2 );
daspect( [1 1 1] )

Copyright 2017, Leonard R. Wayne, Washington, District of Columbia, United States of America. ALL RIGHTS RESERVED.