Ellipsoid function R - search if point is in - R script

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) {
#returns true if (x,y,z) fits inside the ellipsoid
}
+3
source share
1 answer

The point (x,y,z)is inside the if

(x-x0) ^ 2 / a ^ 2 + (y-y0) ^ 2 / b ^ 2 + (z-z0) ^ 2 / c ^ 2 <1,

where aand bare the equatorial radii (along the x and y axes), and cis the polar radius (along the z axis), i.e. square root of the diagonal shape. The center of the ellipsoid is indicated (x0, y0, z0)(a variable centerin your function).

+7
source

All Articles