# rectangle

Create 2-D rectangle object

## Syntax

`rectanglerectangle('Position',[x,y,w,h])rectangle('Curvature',[x,y])rectangle('PropertyName',propertyvalue,...)h = rectangle(...)`

## Properties

For a list of properties, see Rectangle Properties.

## Description

`rectangle` draws a rectangle with `Position` `[0,0,1,1]` and `Curvature` `[0,0]` (i.e., no curvature).

`rectangle('Position',[x,y,w,h])` draws the rectangle from the point `x`,`y` and having a width of `w` and a height of `h`. Specify values in axes data units.

Note that, to display a rectangle in the specified proportions, you need to set the axes data aspect ratio so that one unit is of equal length along both the x and y axes. You can do this with the command `axis` `equal` or `daspect``([1,1,1])`.

`rectangle('Curvature',[x,y])` specifies the curvature of the rectangle sides, enabling it to vary from a rectangle to an ellipse. The horizontal curvature `x` is the fraction of width of the rectangle that is curved along the top and bottom edges. The vertical curvature `y` is the fraction of the height of the rectangle that is curved along the left and right edges.

The values of `x` and `y` can range from `0` (no curvature) to `1` (maximum curvature). A value of `[0,0]` creates a rectangle with square sides. A value of `[1,1]` creates an ellipse. If you specify only one value for `Curvature`, then the same length (in axes data units) is curved along both horizontal and vertical sides. The amount of curvature is determined by the shorter dimension.

`rectangle('PropertyName',propertyvalue,...)` draws the rectangle using the values for the property name/property value pairs specified and default values for all other properties. For a description of the properties, see Rectangle Properties.

`h = rectangle(...)` returns the handle of the rectangle object created.

## Examples

collapse all

### Draw Rectangle

Draw a rectangle that has a lower left corner at the point (1,2) and an upper right corner at (6,8). The width of the rectangle is 5 units and the height is 6 units. Additionally, change the axis limits.

```rectangle('Position',[1 2 5 6]) axis([0 10 0 10]) ```

### Draw Circle

Draw a circle using the `rectangle` function and setting the `Curvature` property to `[1 1]`. Set the `Position` property to define the smallest rectangle that contains the circle. Draw the circle so that it fills the rectangular area between the points (2,4) and (4,6).

```pos = [2 4 2 2]; rectangle('Position',pos,'Curvature',[1 1]) axis equal ```

Draw a red rectangle using the same position values to show how the circle fills the rectangular area.

```rectangle('Position',pos,'EdgeColor','r') ```

### Rectangle with Different Curvatures

Create a rectangle with a curvature of `[0.8,0.4]`, which produces a rectangle with different horizontal and vertical curvatures. Set the data aspect ratio to `[1,1,1]` so that MATLAB® displays the rectangle in the specified proportions.

```figure rectangle('Position',[0.59,0.35,3.75,1.37],... 'Curvature',[0.8,0.4],... 'LineWidth',2,... 'LineStyle','--') daspect([1,1,1]) ```

Create a rectangle with a curvature of `0.4`.

```figure rectangle('Position',[0.59,0.35,3.75,1.37],... 'Curvature',0.4,... 'LineWidth',2,... 'LineStyle','--') daspect([1,1,1]) ```

Create a rectangle with a curvature of `1`, which produces a rectangle with the shortest side completely round.

```figure rectangle('Position',[0.59,0.35,3.75,1.37],... 'Curvature',1,... 'LineWidth',2,... 'LineStyle','--') daspect([1,1,1]) ```

### Create Red Ellipse

Create an ellipse and color the face red.

```figure rectangle('Position',[1,2,5,10],... 'Curvature',[1,1],... 'FaceColor','r') daspect([1,1,1]) ```

collapse all

### Tips

Rectangles are children of axes and are defined in coordinates of the axes data.