0

I have been using rgl to plot spheres, but now I need to plot ellipsoids. The package includes ellipse3d; however, this seems to be for fitting ellipsoids to data, using matrices and stuff I'm not very good at.

What I want is a simple way to plot ellipsoids, in a similar way to spheres, using the centre coordinates and the scales in each direction. Can anyone help me out?

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
Sam
  • 11
  • 1

2 Answers2

3

If you don't need the ellipse rotated around the axes, then you can just use a diagonal matrix for x (this plots a sphere, and defines the virtual "axes" along the x, y, z axes) and use the centre and scale parameters to shift the location and change the proportions.

plot3d(ellipse3d(diag(3),centre=c(1,2,4),scale=c(1,2,5)))
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • That's just the kind of simplicity I was after - Thanks so much! But is it also possible to change the scale on the axes, to shrink it a bit? – Sam Nov 05 '14 at 13:27
2

There's one in my cda package,

library(cda)
library(rgl) 
## single ellipsoid
plot3d(rgl.ellipsoid(a=2,b=1,c=5))

enter image description here

## multiple ellipsoids, translated and rotated 
cl <- helix(0.5, 1, 36, delta=pi/6, n.smooth=1e3)
sizes <- equal_sizes(0.04,0.02,0.02,NROW(cl$positions))
rgl.ellipsoids(cl$positions, sizes, cl$angles, col="gold") 

enter image description here

baptiste
  • 75,767
  • 19
  • 198
  • 294