我有一个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)))
}
Run Code Online (Sandbox Code Playgroud)
这使得椭圆体具有给定的中心和半径.然后我可以使用以下方法绘制:
q <- quads3d(ellips[,1], ellips[,2], ellips[,3], front="lines",
back="lines", alpha=.5,
lit=FALSE, col=surface.col[1])
Run Code Online (Sandbox Code Playgroud)
但是,我如何确定点(x,y,z)是否落在这个椭圆体内?具体来说,我如何找出椭圆体的半轴?
例如,
fitsInEllipsoid <- function(ellipsoid, x, y, z) {
#returns true if (x,y,z) fits inside the ellipsoid
}
Run Code Online (Sandbox Code Playgroud)
的一点(x,y,z)是,如果里面

其中a和b是赤道半径(沿x和y轴)并且c是极半径(沿z轴),即shape参数对角线的平方根.椭圆体的中心用(x0, y0, z0)(center函数中的变量)表示.