shotGroups (version 0.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)

Arguments

xy
a numerical (n x 2)-matrix with the (x,y)-coordinates of n >= 2 points (1 row of coordinates per point).

Value

  • A list with the following information about the minimum-area bounding box:
  • ptsa (4 x 2)-matrix containing the coordinates of the (ordered) vertices.
  • widthwidth of the box.
  • heightheight of the box.
  • angleorientation of the box' longer edge pointing up as returned by atan2, but in degree.

Warning

This function uses an algorithm with quadratic time complexity, based on the edges of the convex hull. The 'rotating calipers' algorithm would be more efficient.

See Also

drawBox2, getBoundingBox, getMinCircle

Examples

Run this code
xy <- matrix(round(rnorm(16, 100, 15)), ncol=2)
bb <- getMinBBox(xy)                     # minimum bounding box
H  <- chull(xy)                          # convex hull

# plot original points, convex hull, and minimum bounding box
plot(xy, xlim=range(c(xy[ , 1], bb$pts[ , 1])),
         ylim=range(c(xy[ , 2], bb$pts[ , 2])), asp=1, pch=16)
polygon(xy[H, ], col=NA)                 # show convex hull
drawBox2(bb$pts, fg='blue', colCtr='blue', pch=4, cex=2)

bb$width * bb$height                     # box area
bb$angle                                 # box orientation

Run the code above in your browser using DataCamp Workspace