Learn R Programming

shotGroups (version 0.8.2)

getMinEllipse: Minimum enclosing ellipse for a set of 2D-points

Description

Calculates center, shape matrix, and area of the minimum enclosing ellipse given a set of 2D-coordinates using Khachiyan's algorithm.

Usage

getMinEllipse(xy, tol = 0.001, max_iter = 1000)

# S3 method for data.frame getMinEllipse(xy, tol = 0.001, max_iter = 1000)

# S3 method for default getMinEllipse(xy, tol = 0.001, max_iter = 1000)

Value

A list containing the center, (2 x 2)-shape matrix, and area of the ellipse.

ctr

a numerical 2-vector giving the (x,y)-coordinates of the ellipse's center.

E

a numerical positive definite (2 x 2)-matrix defining the ellipse in the form ((x-c)' E (x-c)) <= 1

cov

matrix, whose eigen-structure determines shape of ellipse. Inverse of E. Useful for plotting with drawEllipse.

area

a numerical value giving the area of the ellipse.

shape

a numerical vector with the orientation of the ellipse's major axis pointing up as returned by atan2 (but in degree), the aspect ratio of the ellipse (square root of condition index kappa), its flattening (1 - inverse aspect ratio) as well as the trace and determinant of the covariance matrix.

size

a numerical vector with the lengths of the semi-axes of the ellipse.

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.

tol

numerical tolerance value. Should be < 1.

max_iter

maximum number of iterations.

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.

References

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

Todd MJ and Yildrim EA. On Khachiyan's Algorithm for the Computation of Minimum Volume Enclosing Ellipsoids. Discrete Applied Mathematics 2007: 155: 1731-1744. https://people.orie.cornell.edu/miketodd/TYKhach.pdf

Jacob. Bounding ellipse. https://stackoverflow.com/a/1768440.

See Also

drawEllipse, getMinCircle, getMinBBox, getBoundingBox

Examples

Run this code
# coordinates given by a suitable data frame
me <- getMinEllipse(DFsavage, tol=0.001)

plot(point.y ~ point.x, data=DFsavage, pch=16, asp=1)
drawEllipse(me, fg='blue')

# coordinates given by a matrix
if (FALSE) {
xy <- matrix(round(rnorm(20, 100, 15), 2), ncol=2)
getMinEllipse(xy, tol=0.001)
}

Run the code above in your browser using DataLab