[R] shapes in rgl

Duncan Murdoch murdoch at stats.uwo.ca
Wed May 24 00:52:44 CEST 2006


On 5/23/2006 5:00 PM, Duncan Golicher wrote:
> Thanks so much Greg. I was thinking along similar lines but just 
> couldn't see how to do it. Great trick, just what I needed. They didn't 
> have to be solid, in fact these are potentially more pine like. Now, I 
> wonder what other shapes can be made this way.....

Take a look at the qmesh3d man page, and demo(shapes3d) for more ideas.
The nice thing about the qmesh stuff is that you can define a shape 
once, then transform it to display it in different locations, or at 
different sizes, etc.

Duncan Murdoch

> 
> Duncan
> 
> Greg Snow wrote:
> 
>> Try this function (and modify it to your hearts content):
>>
>> 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,
>>
>>  
>>
> 
>



More information about the R-help mailing list