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