I have a three-dimensional ellipsoidal function:
ellipsoid <- function(center=c(0, 0, 0), radius=1, shape=diag(3),
segments=51) {
angles <- (0:segments)*2*pi/segments
ecoord2 <- function(p) {
c(cos(p[1])*sin(p[2]), sin(p[1])*sin(p[2]), cos(p[2])) }
unit.sphere <- t(apply(expand.grid(angles, angles), 1, ecoord2))
t(center + radius * t(unit.sphere %*% chol(shape)))
}
making an ellipsoid with a given center and radius. Then I can draw it using:
q <- quads3d(ellips[,1], ellips[,2], ellips[,3], front="lines",
back="lines", alpha=.5,
lit=FALSE, col=surface.col[1])
But how can I determine if a point (x, y, z) falls inside this ellipsoid? In particular, how can I determine the semi-axes of an ellipsoid?
eg,
fitsInEllipsoid <- function(ellipsoid, x, y, z) {
}
source
share