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
Can you give a little more detail? Do you want the nice 3d shading effect? Or is an ellipse, 2 lines and another ellipse good enough? Does the viewing angle matter (flatness of ellipses). Do the cylinders need to be placed at certain locations? Or are you trying to do a barplot with 3d cylinders instead of bars? (please, please, please say no to that last one) -- 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. >
Check out the 'rgl' package for creating 3D objects. On Wed, Mar 26, 2008 at 3:02 PM, Hans-Joachim Klemmt <h-j.klemmt at lrz.tu-muenchen.de> wrote:> 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Hans-Joachim Klemmt <h-j.klemmt <at> lrz.tu-muenchen.de> writes:> > 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 >Here's a starting point, if you want to use the rgl package: cylinder3d <- function(len=1,rad=1,n=30,ctr=c(0,0,0), trans = par3d("userMatrix"),...) { if (missing(trans) && !rgl.cur()) trans <- diag(4) degvec <- seq(0,2*pi,length=n) circ <- cbind(rad*cos(degvec),rad*sin(degvec)) x <- rad*cos(degvec) y <- rad*sin(degvec) p <- c(1,1,rep(2:n,each=4),1,1) z <- rep(c(-1,1,1,-1)*len/2,n) quads3d(x[p],y[p],z,...) } it doesn't draw the ends of the cylinder. good luck, Ben Bolker
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. >