getMinBBox | R Documentation |
Calculates the vertices of the minimum-area, possibly oriented bounding box given a set of 2D-coordinates.
getMinBBox(xy) ## S3 method for class 'data.frame' getMinBBox(xy) ## Default S3 method: getMinBBox(xy)
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 |
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).
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: ( |
diag |
length of box diagonal. |
angle |
orientation of the box' longer edge pointing up as returned by |
Computational Geometry Algorithms Library. 2021. CGAL Chapter 65: Bounding Volumes. https://doc.cgal.org/Manual/latest/doc_html/cgal_manual/Bounding_volumes/Chapter_main.html Toussaint, G. T. 1983. Solving geometric problems with the rotating calipers. In: Proceedings of the 1983 IEEE MELECON. Athens, Greece: IEEE Computer Society.
drawBox2
,
getBoundingBox
,
getMinCircle
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.