Learn R Programming

shotGroups (version 0.7.1)

getMinBBox: Minimum-area bounding box for a set of 2D-points

Description

Calculates the vertices of the minimum-area, possibly oriented bounding box given a set of 2D-coordinates.

Usage

getMinBBox(xy)
"getMinBBox"(xy)
"getMinBBox"(xy)

Arguments

xy
either a numerical (n x 2)-matrix with the (x,y)-coordinates of n >= 2 points (1 row of coordinates per point), or a data frame with either the variables X, Y or Point.X, Point.Y.

Value

A list with the following information about the minimum-area bounding box:
pts
a (4 x 2)-matrix containing the coordinates of the (ordered) vertices.
width
width of the box.
height
height of the box.
FoM
figure of merit, i.e., the average side length of the box: (width + height) / 2.
diag
length of box diagonal.
angle
orientation of the box' longer edge pointing up as returned by atan2, but in degree.

Details

No coordinate transforms are done (unlike in groupLocation, groupShape, groupSpread), i.e., origin is not assumed to be in top-left corner, and points are not taken relative to point of aim. Uses the rotating calipers algorithm (Toussaint, 1983).

References

Toussaint, G. T. (1983). Solving geometric problems with the rotating calipers. In Proceedings of the 1983 IEEE MELECON. Athens, Greece: IEEE Computer Society.

See Also

drawBox2, getBoundingBox, getMinCircle

Examples

Run this code
# coordinates given by a suitable data frame
bb <- getMinBBox(DFsavage)               # minimum bounding box

# plot points and minimum bounding box
plot(point.y ~ point.x, data=DFsavage, asp=1,
     xlim=range(bb$pts[ , 1]), ylim=range(bb$pts[ , 2]), pch=16)
drawBox2(bb, fg='blue', colCtr='blue', pch=4, cex=2)

bb$FoM                                   # figure of merit
bb$angle                                 # box orientation

# coordinates given by a matrix
## Not run: 
# xy <- matrix(round(rnorm(16, 100, 15)), ncol=2)
# getMinBBox(xy)
# ## End(Not run)

Run the code above in your browser using DataLab