# [R] drawing lines in 3D (rotating them)

From: <cgenolin_at_u-paris10.fr>
Date: Tue, 20 May 2008 22:19:16 +0200

I write a short function to draw lines in 3D, showing then turning. At some point, I add "delais" to slow down the rotation.

So two questions:

1. I try to find a library to draw animate lines in 3D but I did not find. That surprise me since it is very simple to do. Did I forget to look somewhere ?

If it does not exists and I have to use my own function : 2) Is it possible to use the time wasted in delais for some calculous ? In other word, can I run some calculous during a certain amount of time, then drawing a plot, then calculous then plot...

3) Is there a way to end the rotation less violant than Esc ?

Here is my code :

plot3Dlines <- function(x,y,mean=TRUE,angle=20,delais=100000,color,...){

```    time <- 1:dim(x)[[2]]
var1 <- seq(min(x[,,1],na.rm=TRUE),max(x[,,1],na.rm=TRUE),length.out=11)
var2 <- matrix(NA,length(time),length(var1))#outer(x, y, NA)
```
var2[1,1] <- min(x[,,2],na.rm=TRUE)
var2[length(time),length(var1)] <- max(x[,,2],na.rm=TRUE)     nbLines<-min(100,dim(x)[1])
if(missing(color)){color<-2:(nbLines+1)}else{}     repeat{
```        res <- persp(x=time, y=var1, z=var2, theta = angle,
phi = 10, expand = 0.5, col = "lightblue",
ltheta = 120, shade = 0.75, ticktype = "detailed",
xlab = "time", ylab = "var1", zlab = "var2")
angle <- angle+1
for(i in 1:nbLines){
yy=x[i,,1]
zz=x[i,,2]
lines (trans3d(time, yy, zz, pmat = res),col=color[i])
}
for(k in 1:delais){}
```

}
}
plot3Dlines(data)

Thanks

Christophe

R-help_at_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. Received on Tue 20 May 2008 - 20:38:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 20 May 2008 - 21:30:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.