1

Using this link as a starting point, How to find the smallest ellipse covering a given fraction of a set of points in R?

I would like to create the smallest circle that includes (touches or goes inside) a majority of a set of ellipses, instead of being limited to a set of 2d data points, as the link is.

I'm looking for a circle, as opposed to the ellipse that the ellipsoidhull function produces. Maybe there is a way to configure the shape that ellipsoidhull function produces, that I haven't found yet? My data set is:

The circle will include ellipses named d, b, e, a, i, and look like this: I've added the circle in paint.

library(ggplot2)
library(ggforce)
library(MASS)
library(cluster)
library(car)

d <- data.frame(
  name = c("a", "b", "c", "d", "e", "f", "g", "h", "i"),
  x0 = c(5, 3, 4, 1, 4, 5, 7, 9, 5),
  y0 = c(4, 4, 9, 5, 5, 1, 7, 7, 7),
  a = c(0.9, 0.6, 1.0, 1.1, 1.3, 1.6, 1.4, 0.5, 0.6),
  b = c(0.7, 0.5, 0.6, 0.7, 0.8, 0.7, 0.7, 1.7, 1.8)
)
ggplot(data = d) + geom_ellipse(aes(x0 = x0, y0 = y0, a = a, b = b, angle = 0), fill = "grey", alpha = 0.3)+
geom_text(data=d, aes(x=x0, y=y0, label = name))

#This second part of the code is from the link, which creates an ellipse based on data points. Possibly it could be useful

xy <- cbind(d$x0, d$y0)
fit <- cov.rob(xy, quantile.used = 5, method = "mve")
# Finding the minimum volume ellipse that contains these three points
best_ellipse <- ellipsoidhull( xy[fit$best,] )

plot_min_ellipse <- function(xy, points_in_ellipse, color = "blue") {
  fit <- cov.rob(xy, quantile.used = points_in_ellipse, method = "mve")
  best_ellipse <- ellipsoidhull( xy[fit$best,] )
  lines(predict(best_ellipse), col=color)
}
# The predict() function returns a 2d matrix defining the coordinates of
# the hull of the ellipse 
plot(xy)+ lines(predict(best_ellipse), col="blue")

I believe the algorithm would become the red circle in this plot. Touching or penetrating or enveloping 5 out of 9 ellipses.

9 ellipses and 1 red circle connecting 5 of them

dataes
  • 11
  • 3
  • `?cluster::ellipsoidhull` returns a list that includes `loc: p-dimensional location of the ellipsoid center`, which leaves deciding a logic for selecting the `given fraction of a set of ellipses`, as a kind of inner hull? Circles are ellipses with shared foci. About where would the 'circle' be in the provided plot? – Chris Sep 20 '22 at 14:24
  • I've rewritten the question for the sake of clarity now. – dataes Aug 04 '23 at 12:42
  • And then there's `d`, which happily makes 5 polys as it is equidistant from `i`. For the various `smallest circle` approaches (spatstat, shotGroups, sfcgal, lwgeom) one still has to select which points qualify. On intuition this circle will be in the area of e:b:a group, So, what is the underlying data? – Chris Aug 04 '23 at 14:17
  • The location and size of the red circle that I added in paint is based on my intuition that is the smallest circle that contains/touches 5 ellipses. I don't know how to program it, but perhaps: convert each ellipse into 200 2d x y data points that are around the edge of the ellipse, and make the algorithm search for the smallest circle area that includes at least one x y data points from 5 different sets among a,b,c,d,e,f,g,h,i. – dataes Aug 05 '23 at 11:56

0 Answers0