[R] Two surfaces in one plot with visibility

Duncan Murdoch murdoch.duncan at gmail.com
Tue Feb 14 15:38:34 CET 2012

On 14/02/2012 9:19 AM, Michael Friendly wrote:
> On 2/13/2012 11:15 AM, Duncan Murdoch wrote:
> >  On 13/02/2012 9:24 AM, Sebastian Schubert wrote:
> >>  Hi,
> >>
> >>  I would like plot two surfaces which are each given by vectors x and y,
> >>  and a matrix m(x,y) representing the z coordinate. With persp() I can
> >>  plot both, using par(new=TRUE) I can put it in one plot. However, I
> >>  would like to have the visibility of the surfaces taken into account as
> >>  if they are solid thin surfaces, so that for example the order of the
> >>  plot commands does not matter.
> >>
> >>  Any idea how to do that?
> >
> >  That's really hard in persp(). You'd have to plot the facets of the
> >  surfaces from back to front, and there's no easy way to do that.
> >  I'd recommend using rgl::persp3d, where your graphics hardware will do
> >  the computations of which surface is in front.
> >
> >  Duncan Murdoch
> >
> In addition to using rgl, you might find it useful to use transparent
> colors for one or both surfaces.

That often makes a nicer looking plot, but if the surfaces intersect, it 
won't look very nice along the boundary if both are transparent, because 
of limitations in the algorithm rgl uses.  It should be fine if they 
don't intersect, or only one is transparent.

Duncan Murdoch

More information about the R-help mailing list