fitEllipse: Fit an ellipse

View source: R/Ellipse.R

fitEllipseR Documentation

Fit an ellipse

Description

Fit an ellipse to a set of points.

Usage

fitEllipse(points)

Arguments

points

numeric matrix with two columns, one point per row

Value

An Ellipse object representing the fitted ellipse. The residual sum of squares is given in the RSS attribute.

Examples

library(PlaneGeometry)
# We add some noise to 30 points on an ellipse:
ell <- Ellipse$new(c(1, 1), 3, 2, 30)
set.seed(666L)
points <- ell$randomPoints(30, "on") + matrix(rnorm(30*2, sd = 0.2), ncol = 2)
# Now we fit an ellipse to these points:
ellFitted <- fitEllipse(points)
# let's draw all this stuff:
box <- ell$boundingbox()
plot(NULL, asp = 1, xlim = box$x, ylim = box$y, xlab = NA, ylab = NA)
draw(ell, border = "blue", lwd = 2)
points(points, pch = 19)
draw(ellFitted, border = "green", lwd = 2)

PlaneGeometry documentation built on Aug. 10, 2023, 1:09 a.m.