Learn R Programming

shotGroups (version 0.7.1)

getMinCircle: Minimum enclosing circle for a set of 2D-points

Description

Calculates center and radius of the minimum enclosing circle given a set of 2D-coordinates.

Usage

getMinCircle(xy)
"getMinCircle"(xy)
"getMinCircle"(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 containing the center and radius of the circle.
ctr
a numerical 2-vector giving the (x,y)-coordinates of the circle's center.
rad
a numerical value giving the radius of the circle.

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 Skyum algorithm based on the convex hull.

References

Skyum, S. 1991. A simple algorithm for computing the smallest enclosing circle. Information Processing Letters 37(3), 121-125.

See Also

drawCircle, getMinBBox, getBoundingBox

Examples

Run this code
# coordinates given by a suitable data frame
mc <- getMinCircle(DFsavage)

# determine axis limits so that circle will be visible
xLims <- mc$ctr[1] + c(-mc$rad, mc$rad)
yLims <- mc$ctr[2] + c(-mc$rad, mc$rad)
plot(point.y ~ point.x, data=DFsavage,
     pch=16, asp=1, xlim=xLims, ylim=yLims)
drawCircle(mc, fg='blue')

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

Run the code above in your browser using DataLab