我有一个 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
}