ellipsoid: Calculate an ellipsoid in 3D

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/ellipsoid.R

Description

Calculates a qmesh3d object representing 3D ellipsoid with given center and shape matrix. The function allows for degenerate ellipsoids where the smape matrix has rank < 3 and plots as an ellipse or a line.

Usage

1
ellipsoid(center, shape, radius = 1, segments = 60, warn.rank = FALSE)

Arguments

center

A vector of length 3 giving the center of the 3D ellipsoid, typically the mean vector of a data matrix.

shape

A 3 x 3 matrix giving the shape of the 3D ellipsoid, typical a covariance matrix of a data matrix.

radius

radius of the ellipsoid, with default radius=1, giving a standard ellipsoid. For a multivariate sample with dfe degrees of freedom associated with shape, an ellipsoid of level coverage can be calculated using radius=sqrt(3 * qf(level, 3, dfe)).

segments

number of line segments to use in each direction in the wire-frame representation of the ellipsoid

warn.rank

warn if the shape matrix is of rank < 3?

Details

The ellipsoid is calculated by transforming a unit sphere by the Cholesky square root of the shape matrix, and translating to the center.

The ellipsoid can be plotted with plot3d

Value

A qmesh3d object

Author(s)

Michael Friendly and John Fox, extending Duncan Murdoch

See Also

data.Ell3d, Ell3d

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (center, shape, radius = 1, segments = 60, warn.rank = FALSE) 
{
    degvec <- seq(0, 2 * pi, length = segments)
    ecoord2 <- function(p) c(cos(p[1]) * sin(p[2]), sin(p[1]) * 
        sin(p[2]), cos(p[2]))
    v <- t(apply(expand.grid(degvec, degvec), 1, ecoord2))
    if (!warn.rank) {
        warn <- options(warn = -1)
        on.exit(options(warn))
    }
    Q <- chol(shape, pivot = TRUE)
    order <- order(attr(Q, "pivot"))
    v <- center + radius * t(v %*% Q[, order])
    v <- rbind(v, rep(1, ncol(v)))
    e <- expand.grid(1:(segments - 1), 1:segments)
    i1 <- apply(e, 1, function(z) z[1] + segments * (z[2] - 1))
    i2 <- i1 + 1
    i3 <- (i1 + segments - 1)%%segments^2 + 1
    i4 <- (i2 + segments - 1)%%segments^2 + 1
    i <- rbind(i1, i2, i4, i3)
    x <- asEuclidean(t(v))
    ellips <- qmesh3d(v, i)
    return(ellips)
  }

p3d documentation built on May 2, 2019, 5:25 p.m.