[R] Want to draw 3D cylinder objects

Greg Snow Greg.Snow at imail.org
Thu Mar 27 15:55:25 CET 2008


Here is one approach to drawing simple cylinders at specified locations, the height, width, and angle should all be numbers between 0 and 1 and you may want to rewrite the ms.cylinder function below so that the arguments are more meaningful relative to the input data that you want to use:


> library(TeachingDemos)
> 
> ms.cylinder <- function(height, width, angle) {
+ theta <- seq(2*pi, 0, length=200)
+ x1 <- cos(theta) * width
+ y1 <- sin(theta) * width * angle
+ 
+ x <- c(x1, x1[1:100], x1[100])
+ y <- c(y1 + height/2, y1[1:100]-height/2, y1[100]+height/2)
+ 
+ return(cbind(x,y))
+ }
> 
> x <- 0:8 %/% 3
> y <- 0:8 %% 3
> 
> h <- runif(9)
> w <- runif(9)
> a <- runif(9)
> 
> 
> plot(x,y, xlim=c(-.5,2.5), ylim=c(-.5,2.5), type='n')
> my.symbols(x,y,ms.cylinder, height=h, width=w, angle=a)

Hope this helps,

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

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of Hans-Joachim Klemmt
> Sent: Wednesday, March 26, 2008 2:03 PM
> To: r-help at r-project.org
> Subject: [R] Want to draw 3D cylinder objects
> 
> Hello,
> 
> I want to draw 3D cylinder objects in R.
> 
> Given is the length and the diameter of the cylinder.
> 
> Has anybody an example?
> 
> Thank you very much!
> 
> Best regards
> 
> --
> ----------------------
> 
> Dr. Hans-Joachim Klemmt
> 
> Forstoberrat
> Organisationsprogrammierer IHK
> 
> 
> Bayerische Landesanstalt für Wald und Forstwirtschaft
> 
> zugewiesen an
> 
> Lehrstuhl für Waldwachstumskunde
> Technische Universität München
> Am Hochanger 13
> 
> 85354 Freising
> 
> Tel.: 08161/ 7147-14
> Fax : 08161/ 7147-21
> 
> eMail: h-j.klemmt at lrz.tum.de
> 
> ______________________________________________
> 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.
> 



More information about the R-help mailing list