Re: [R] Want to draw 3D cylinder objects

From: Ben Bolker <>
Date: Thu, 27 Mar 2008 02:05:03 +0000 (UTC)

Hans-Joachim Klemmt <h-j.klemmt <at>> 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)


  it doesn't draw the ends of the cylinder.

  good luck,
    Ben Bolker mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 27 Mar 2008 - 05:05: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 Thu 27 Mar 2008 - 05:30:24 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive