On 20/04/2012 2:48 PM, Nate Cermak wrote:
Hello R-help!
I am trying to draw series of lines in 3d, and I am not sure how to get the
depth set up properly - lines that are in front of other lines appear to be
behind and vice versa. I've been doing this by first generating an empty
persp plot, then adding lines via the data into trans3d followed by lines
(this is probably a bad approach, but it was the first one I could get
working).

The only possibility with persp is for you to draw the ones that need to be behind first, the ones in front later. Persp can't do it, you have to. The rgl package can do the sorting, but there are other limitations in it that you might not find acceptable, particularly in output formats.

Duncan Murdoch


Here is a semi-contrived minimal example of my problem:

###########################################################
#line 1
x1=0:10;
y1=rep(0,11);
z1 = rep(5,11);

#line 2
x2=y2=z2 = 0:10

# make empty persp plot (awful hack to make a surface out of view)
pmat = persp(x=c(-10.1,-10), y=c(-10.1,-10), z=matrix(c(0,.1,0,.1),
nrow=2),
     xlim=c(0,10), ylim=c(0,10), zlim=c(0,10), xlab='x', ylab='y', zlab='z')

# now draw the lines
lines( trans3d(x1, y1, z1,pmat), col="grey", lwd=3)
lines( trans3d(x2, y2, z2,pmat), col="red", lwd=3)
#############################################################

Ideally, the red line would occur behind the grey line (and in this
example, I could very simply switch the order and fix the problem), but I'm
not sure how to make this happen in the general case. I have a dataset of
more like a hundred lines, many of which sort of corkscrew around one
another. How can I ensure that the plotting of the lines respects the
depth? Is there a better function I could be using for this? I tried plot3d
in rgl and scatter3d in Rcmdr,  but both crash R on my system.

Thanks so much in advance!

-nate cermak

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to