# bbox2points

Convert rectangle to corner points list

## Syntax

``points = bbox2points(rectangle)``

## Description

example

````points = bbox2points(rectangle)` converts the input rectangle, into a list of four [x y] corner points. The `rectangle` input must be either a single bounding box or a set of bounding boxes.```

## Examples

collapse all

Define a bounding box.

`bbox = [10,20,50,60];`

Convert the bounding box to a list of four points.

`points = bbox2points(bbox);`

Define a rotation transformation.

```theta = 10; tform = affine2d([cosd(theta) -sind(theta) 0; sind(theta) cosd(theta) 0; 0 0 1]);```

Apply the rotation.

`points2 = transformPointsForward(tform,points);`

Close the polygon for display.

`points2(end+1,:) = points2(1,:);`

Plot the rotated box.

`plot(points2(:,1),points2(:,2), '*-');`

## Input Arguments

collapse all

Bounding box, specified as a 4-element vector, 5-element vector, M-by-4 matrix, or M-by-5 matrix.

Bounding BoxExample

For one or more rectangles, specify one of:

• An M-by-4 matrix where each row specifies a rectangle as $\left[\begin{array}{cccc}x& y& width& height\end{array}\right]$.

`$\left[\begin{array}{cccc}{x}_{1}& {y}_{1}& widt{h}_{1}& heigh{t}_{1}\\ {x}_{2}& {y}_{2}& widt{h}_{2}& heigh{t}_{2}\\ ⋮& ⋮& ⋮& ⋮\\ {x}_{M}& {y}_{M}& widt{h}_{M}& heigh{t}_{M}\end{array}\right]$`

• An M-by-5 numeric matrix with rows of the form [xctr yctr w h yaw], where:

• M is the number of rotated rectangles.

• xctr and yctr specify the center of the rectangle.

• w specifies the width of the rectangle, which is its length along the x-axis before rotation.

• h specifies the height of the rectangle, which is its length along the y-axis before rotation.

• yaw specifies the rotation angle in degrees. The rotation is clockwise-positive around the center of the bounding box.

Data Types: `single` | `double` | `int16` | `int32` | `uint16` | `uint32`

## Output Arguments

collapse all

Rectangle corner coordinates, returned as a 4-by-2 matrix of [x,y] coordinates, or a 4-by-2-by-M array of [x,y] coordinates. The output points for the rectangle are listed counterclockwise starting from the upper-left corner.

• For a single input bounding box, the function returns the 4-by-2 matrix.

• For multiple input bounding boxes, the function returns the 4-by-2-M array for M bounding boxes.

Data Types: `single` | `double` | `int16` | `int32` | `uint16` | `uint32`

## Version History

Introduced in R2014b