Main Content


Convert rectangle to corner points list



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.


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 [xywidthheight].


  • 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.

Two rectangles, M=2, showing width and height. One rectangle shows x1, y1 point in the upper-left corner of rectangle 1 and the other rectangle as x2,y2.

Square rectangle rotated by -30 degrees.

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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2014b

See Also