I want to draw a clyinder between two planes. I want to specify the distance between the planes and position and radius of the cylinder.


I would like to use tikz-3dplot, because it allows a free rotation of the Viewpoint if everything is implemented with it.

There are a few Threads in which the creation of 3D bodies in TikZ, Drawing simple 3D cylinders in TikZ and Drawing 3D cylinder have been discussed.

Unfortunately those solution seem not to work with tikz-3dplot, because they all manipulate the 'Viewpoint' themself. This leads to the Problem, that a manipulation of the viewpoint with \tdplotsetmaincoords only rotates all Objects except the Cylinders.

Result at the moment with tikz Result at the moment with Tikz - front view

Another User had a very similar question which yielded no answer yet. How to draw a 3d cylinder using TikZ-3dplot?

To summarize: I want to draw a cylinder in 3d using tikz-3dplot. At the Moment i can draw the circle at the end of the cylinder and a line from border to border, which only recognizes rotation around the x-axis. The Question is how can i put the lines correctly at the side of the cylinder. Solution at the moment

Example of Code:

\documentclass[convert = false, tikz]{standalone}




%Configure here Rotation around x and y axis


\begin{tikzpicture}[ tdplot_main_coords]

  \coordinate (O) at (0, 0, 0);

    \draw[-latex] (O) -- (-8, 0, 0) node[font = \small, pos = 1.1] {\(x\)};
    \draw[-latex] (O) -- (0, 6, 0) node[font = \small, pos = 1.1] {\(y\)};
    \draw[-latex] (O) -- (0, 0, 6) node[font = \small, pos = 1.1] {\(z\)};

    % define size of planes

    \filldraw[blue, opacity = .2]
         (0, 0, 0)
          -- (0, \planesize, 0)
          -- (0, \planesize, \planesize)
          -- (0, 0, \planesize)
          -- cycle;

    %Define Plane in which the circles of the cylinder are drawn.

    %\tdplotdrawarc[coordinate system, draw styles]{center}{r}{angle start}{angle end}{label options}{label}
    %circle on first plane

    %circle on second plane  

    %line from middle to middle
    \draw[tdplot_rotated_coords] (1,1,0) -- (1, 1, 4) node[font = \small, pos = 1.1] {};

    %First Edge of cylinder

    \filldraw[blue, opacity = .2]
             (-4, 0, 0)
              -- (-4, \planesize, 0)
              -- (-4, \planesize, \planesize)
              -- (-4, 0, \planesize)
              -- cycle;
  • Sebastian, you're welcome, but that comment should be a comment and not part of the question. Secondly, could you please explain why you included my solution in your question? I'm having a hard time trying to figure out the problem here. :P (You can comment below here.) – Alenanno Oct 16 '13 at 20:08
  • @Alemanno i basically want a way to draw the first picture and be able to expand it to three planes and multiple cylinders. I thought that Tikz-3dplot would be the best way to do something like that. Unfortunately there seems to be no support for cylinders. That's the reason why I am trying to construct them myself and why i am asking for help. I will abandon tikz in a blink if you know a better tool to do the job. I only know Blender, but that would be overkill i guess. – Sebastian Schmitz Oct 17 '13 at 9:08
  • Showing a mock-up of your desired final result would be helpful. Your first image looks like the one I've been doing so I'm not sure what you want exactly. :D – Alenanno Oct 17 '13 at 9:15
  • @Alenanno i reformulated everything. The Problem is, that it's just a coincidence, that the Picture in your Answer looks correct. The Coordinates of the circle and of the plane are completly different. – Sebastian Schmitz Oct 17 '13 at 9:49

Attempted with pgfplots:



    axis equal image,
    axis lines=center,
    mesh/interior colormap={blue}{color=(blue!20)color=(blue!20)},
    z buffer=sort]
    \addplot3 [domain=0:8,y domain=0:8,surf,opacity=0.6,shader=flat,samples=2] (x,8,y);
    \addplot3 [domain=0:8,y domain=0:2*pi,mesh,black,samples=25] ({4+1*cos(deg(y))},{8},{4+1*sin(deg(y))});
    \addplot3 [domain=0:8,y domain=0:2*pi,surf,shader=interp,samples=25] ({4+1*cos(deg(y))},{x},{4+1*sin(deg(y))});
    \addplot3 [domain=0:8,y domain=0:2*pi,mesh,black,samples=25] ({4+1*cos(deg(y))},{0},{4+1*sin(deg(y))});



enter image description here






draw planes y=0 and y=8. While command


drawing a cylinder (a+bcos(y),x,a+bsin(y)), where a=4 and b=1. I also added:


to mark where the cylinder and plane intercept, as pgfplots couldn't handle that automatically.

You can rotate the view point freely by changing the view={...}{...} option. For example, view={60}{30} will give you:

enter image description here

Most of the options of pgfplots are quite self-explanatory, refer to the package document for further detail.

  • Is it possible to blacken the "edge" of the cylinder? So that the tube is transparent and only two lines connect both circles of the cylinder? – Sebastian Schmitz Oct 18 '13 at 17:13
  • 1
    @SebastianSchmitz: You can use options such as mesh or shader=faceted to emphasize the edges. But unfortunately that will mark all the line that are sampled. As far as I know there is no way to remove all the edges except two. – Francis Oct 18 '13 at 17:39

The following answer uses Asymptote rather than TikZ-3dplot, but otherwise does (I think) everything you ask.



import solids;

//currentprojection = obliqueX(angle=55);
currentprojection = orthographic(2X+Y+Z);

path3 xaxis = O -- -6X;
draw(xaxis, arrow=Arrow3);
label(Label("$x$", position=EndPoint), xaxis);

path3 yaxis = O -- 6Y;
draw(yaxis, arrow=Arrow3);
label(Label("$y$", position=EndPoint), yaxis);

path3 zaxis = O -- 6Z;
draw(zaxis, arrow=Arrow3);
label(Label("$z$", position=EndPoint), zaxis);

triple circlecenter = Y+Z;
real radius = 0.5;
triple normal = -X;
// center = Y+Z, radius=0.5, height=4, normal=-X
revolution cylinder = cylinder(circlecenter, radius, 4, normal);

surface plane = surface(O -- 4Y -- 4Y+4Z -- 4Z -- cycle);
material planecolor = material(lightblue+opacity(0.5), emissivepen=lightblue);
draw(shift(-4X) * plane, planecolor);

//Block out everything behind the cylinder.
draw(surface(cylinder), emissive(white));

draw(plane, planecolor);

draw(surface(circle(circlecenter, radius, normal)), emissive(white));



The result:

enter image description here

If you change the projection (by changing which of the two lines starting currentprojection = is commented out), you get the following:

enter image description here


Not sure how to answer the "theoretical" part of your question because I'm not really an expert on this subject. But if you simply wanted a solution to make your cylinder look good, then maybe I found one.

It's not the best and it's actually just a sort of "hack/trick" but it works.

cylinder image

What I changed was to move the cylinder code (the one below) to before the filldraw commands:

    % This is a x-growing cylinder
    \tdcylxy{0}{0}{2}{0.5}{3} % y z x  r h

And then repost the same code after the filldraw commands, but this time changing the H value to 0, so that the circle appears in front.

Your Answer

