Skip to content
Prev 157021 / 398506 Next

rgl: ellipse3d with axes

On 24/09/2008 10:12 AM, Michael Friendly wrote:
That's easy, but it doesn't give you the principal axes of the ellipse. 
  Just use

axes %*% chol(cov)

If you start with a unit sphere, this will give you points on its 
surface, but not the ones you want.  For those you need the SVD or 
eigenvectors.  This looks like it does what you want:

axes <- matrix(
     c(0, 0, 0, # added origin
        0, 0, -1,   0, 0, 1,
        0, -1, 0,   0, 1,  0,
        -1, 0, 0,   1, 0, 0),  7, 3, byrow=TRUE)
axes <- axes[c(1,2,1,3,1,4,1,5,1,6,1,7),]  # add the origin before each

cov <- cov(trees)
eigen <- eigen(cov)
shade3d(ellipse3d(cov, t=1, alpha=0.2, col='red'))
segments3d(axes %*% sqrt(diag(eigen$values)) %*% t(eigen$vectors))

Duncan Murdoch