У меня есть 3D-функция эллипсоида:
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)))
}
, которая создает эллипсоид с заданным центром и радиусом.Затем я могу нарисовать его, используя:
q <- quads3d(ellips[,1], ellips[,2], ellips[,3], front="lines",
back="lines", alpha=.5,
lit=FALSE, col=surface.col[1])
Но как я могу определить, находится ли точка (x, y, z) внутри этого эллипсоида?В частности, как я могу выяснить полуоси эллипсоида?
например,
fitsInEllipsoid <- function(ellipsoid, x, y, z) {
#returns true if (x,y,z) fits inside the ellipsoid
}