Re: [R] shapes in rgl

From: Greg Snow <Greg.Snow_at_intermountainmail.org>
Date: Wed 24 May 2006 - 05:06:25 EST

rgl.cones <- function(x,y,z,h=1,r=0.25, n=36, ...){

r <- rep(r, length.out=length(x))
h <- rep(h, length.out=length(x))

step <- 2*pi/n
for (i in seq(along=x)){

```      for (j in seq(0, 2*pi-step, length=n)){
tmp.x <- x[i] + c(0, cos(j)*r[i], cos(j+step)*r[i])
tmp.z <- z[i] + c(0, sin(j)*r[i], sin(j+step)*r[i])
tmp.y <- y[i] + h[i]/2*c(1,-1,-1)

rgl.triangles(tmp.x,tmp.y,tmp.z,...)
}
```

}
}

Hope this helps,

```--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow@intermountainmail.org
(801) 408-8111

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Duncan Golicher
Sent: Tuesday, May 23, 2006 12:29 PM
To: r-help@stat.math.ethz.ch
Subject: [R] shapes in rgl

Does anyone have a way of producing solid shapes other than spheres in rgl? I am using rgl to produce a simple visualisation of a forest model results using "lollipops". Its just a bit of fun, but as many of the trees are pines I would like to depict their crowns as cones. If there is a solution I need it to work under windows.
Here is the example.

library(rgl)
library(misc3d)

rgl.bg(color="white")
x<-rep(x,each=3)
y<-rep(y,each=3)
a<-seq(3,length(x),by=3)
y[a]<-NA
x[a]<-NA
z[a]<-NA
a<-seq(1,length(x),by=3)
z[a]<-0
rgl.bbox(color="black", emission="lightgreen", specular="#3333FF", shininess=5, alpha=0.8 ) }

x<-runif(100,0,100)
y<-runif(100,0,100)
z<-runif(100,10,30)

Thanks,

Duncan Golicher

--
Dr Duncan Golicher
Ecologia y Sistematica Terrestre
El Colegio de la Frontera Sur
San Cristobal de Las Casas,
Chiapas, Mexico

Email: dgoliche@sclc.ecosur.mx

Tel: 967 674 9000 ext 1310
Fax: 967 678 2322
Celular: 044 9671041021

United Kingdom Skypein; 020 7870 6251
Skype name: duncangolicher

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help