boundingbox

Smallest axis-aligned rectangle that contains a polyshape.

Category: Mathematics > Computational Geometry

Syntax

[xlim, ylim] = boundingbox(pshape)

Returns the x and y limits of the bounding box.

Description

The limits are the minimum and maximum vertex coordinates over all boundaries. They are handy for setting axes limits, for a quick overlap rejection test, or for sizing a grid of query points around the shape.

For an empty polyshape, the limits are empty or NaN.

Input arguments

pshape
A polyshape object.

Output arguments

xlim
Two-element row [xmin xmax].
ylim
Two-element row [ymin ymax].

Example

Limits of a triangle

P = polyshape([1 5 3], [2 2 6]);
[xl, yl] = boundingbox(P)
Output
xl = 1×2

     1     5
yl = 1×2

     2     6

Notes

Use the two-output form. Call with a single output only if you are sure how your MATLAB version packs the result.

See also

polyshape overlaps rectint centroid