16

I can draw the cylinder:

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{center}
\begin{tikzpicture}
  \node [cylinder, black, rotate=180, draw,
    minimum height=5cm, minimum width=2cm] (c) {};  
\end{tikzpicture}
\end{center}
\end{document}

But, I can't even draw a chessboard in the lateral area of cylinder, as in the following figure enter image description here

  • 1
    Sidenote: In case you are making this for something actually related to chess: Keep in mind that the board is 8x8. – Dennis Jaheruddin Feb 2 '15 at 16:02
  • @DennisJaheruddin There are variations... – cfr Feb 2 '15 at 17:05
21

The following solution uses the plot command to draw the curved lines. The chessboard like fields are created by drawing each second stripe in horizontal and vertical direction and the even odd rule for filling.

\documentclass{article}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}[
    x=10mm,
    y=10mm,
    z={(2.5mm, 0)},
  ]
    \newcommand*{\CylinderLength}{5}
    \newcommand*{\CylinderRadius}{1}
    \newcommand*{\HorizontalStripes}{5}
    \newcommand*{\VerticalStripes}{10}
    \pgfmathsetmacro{\HorizontalStripeAngle}{180/\HorizontalStripes}
    \draw
      (\CylinderLength, \CylinderRadius) 
      -- plot[domain=90:270, smooth, variable=\t]
         (0, {\CylinderRadius*sin(\t)}, {\CylinderRadius*cos(\t)})
      -- ++(\CylinderLength, 0) 
      plot[domain=0:360, smooth cycle, variable=\t]
      (\CylinderLength, {\CylinderRadius*sin(\t)}, {\CylinderRadius*cos(\t)})
    ;
    \fill[black, even odd rule]
      % Vertical stripes
      \foreach \x in {2, 4, ..., \VerticalStripes} { 
        plot[domain=90:270, smooth, variable=\t] 
        ({(\x-1)*\CylinderLength/\VerticalStripes},
          {\CylinderRadius*sin(\t)}, {\CylinderRadius*cos(\t)})  
        -- ++(\CylinderLength/\VerticalStripes, 0)
        -- plot[domain=90:270, smooth, variable=\t]  
           (\x*\CylinderLength/\VerticalStripes,
             {\CylinderRadius*sin(-\t)}, {\CylinderRadius*cos(-\t)})
        -- cycle
      }
      % Horizontal stripes
      \foreach \y in {2, 4, ..., \HorizontalStripes} {
        plot[domain=90+(\y-1)*\HorizontalStripeAngle:
                    90+\y*\HorizontalStripeAngle,
             smooth, variable=\t]
        (0, {\CylinderRadius*sin(\t)}, {\CylinderRadius*cos(\t)})
        -- ++(\CylinderLength, 0)
        -- plot[domain=-90-\y*\HorizontalStripeAngle:
                       -90-(\y-1)*\HorizontalStripeAngle,
                smooth, variable=\t]
           (\CylinderLength, {\CylinderRadius*sin(-\t)},
             {\CylinderRadius*cos(-\t)})
        -- cycle
      }
    ;  
  \end{tikzpicture}
\end{document}

Result


Remark to the comments, that a semicolon is missing. I cannot reproduce this error message with the versions posted below. The \fill command contains two \foreach loops, for the horizontal and vertical stripes, otherwise the trick with the even odd rule would not work. Thus the semicolon for the \fill command is on line 49 right before the closing \end{tikzpicture}.

 *File List*
 article.cls    2007/10/19 v1.4h Standard LaTeX document class
  size10.clo    2007/10/19 v1.4h Standard LaTeX file (size option)
    tikz.sty    2013/12/13 v3.0.0 (rcs-revision 1.142)
     pgf.sty    2013/12/18 v3.0.0 (rcs-revision 1.14) 
  pgfrcs.sty    2013/12/20 v3.0.0 (rcs-revision 1.28) 
everyshi.sty    2001/05/15 v3.00 EveryShipout Package (MS)
  pgfrcs.code.tex
 pgfcore.sty    2010/04/11 v3.0.0 (rcs-revision 1.7)
graphicx.sty    2014/04/25 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
  keyval.sty    2014/05/08 v1.15 key=value parser (DPC)
graphics.sty    2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
  pdftex.def    2011/05/27 v0.06d Graphics/color for pdfTeX
infwarerr.sty    2010/04/08 v1.3 Providing info/warning/error messages (HO)
 ltxcmds.sty    2011/11/09 v1.22 LaTeX kernel commands for general use (HO)
  pgfsys.sty    2013/11/30 v3.0.0 (rcs-revision 1.47)
  pgfsys.code.tex
pgfsyssoftpath.code.tex    2013/09/09  (rcs-revision 1.9)
pgfsysprotocol.code.tex    2006/10/16  (rcs-revision 1.4)
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
 pgfcore.code.tex
pgfcomp-version-0-65.sty    2007/07/03 v3.0.0 (rcs-revision 1.7)
pgfcomp-version-1-18.sty    2007/07/23 v3.0.0 (rcs-revision 1.1)
  pgffor.sty    2013/12/13 v3.0.0 (rcs-revision 1.25)
 pgfkeys.sty    
 pgfkeys.code.tex
 pgfmath.sty     
 pgfmath.code.tex
  pgffor.code.tex
    tikz.code.tex
supp-pdf.mkii
pdftexcmds.sty    2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO)
ifluatex.sty    2010/03/01 v1.3 Provides the ifluatex switch (HO)
   ifpdf.sty    2011/01/30 v2.3 Provides the ifpdf switch (HO)   
epstopdf-base.sty    2010/02/09 v2.5 Base part for package epstopdf
  grfext.sty    2010/08/19 v1.1 Manage graphics extensions (HO)
kvdefinekeys.sty    2011/04/07 v1.3 Define keys (HO)
kvoptions.sty    2011/06/30 v3.11 Key value format for package options (HO)
kvsetkeys.sty    2012/04/25 v1.16 Key value parser (HO)
etexcmds.sty    2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO)
epstopdf-sys.cfg    2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
 ***********
  • Heiko Oberdiek, Was very beautiful. But, when I compile, has an error on line 34: Package tikz Error: Giving up on this path. Did you forget a semicolon?.See the tikz package documentation for explanation.Type H <return> for immediate help.... } – benedito Feb 2 '15 at 15:09
  • @benedito I just copied and pasted the example and it worked fine. I am using TikZ 3.0.0. – Heiko Oberdiek Feb 2 '15 at 15:39
  • I get the same error, "! Package tikz Error: Giving up on this path. Did you forget a semicolon?" on l.34 } – Pål GD Feb 2 '15 at 17:42
  • @PålGD It's working fine for me, which TikZ version you are using? – Heiko Oberdiek Feb 2 '15 at 18:07
  • @PàlGD, I am using version 3. 0, which I updated today, using Miktex Package Manager – benedito Feb 2 '15 at 18:52
9

Run with xelatex or latex->dvips->ps2pdf

\documentclass[pstricks,border=5pt]{standalone}
\usepackage{pst-solides3d}

\begin{document}
\psset{Decran=15,viewpoint=20 -60 0 rtp2xyz}
\begin{pspicture}(-1,-2)(5,2)
\pstVerb{ /ELEMENT 0 store }
\psSolid[object=cylindrecreux,h=5,r=1.5,RotY=90,ngrid=11 15,
  fcol= 0 2 165 { (black) } for ]% for loop with step 2
\end{pspicture}
\end{document}

enter image description here

And the same for a 8x8 chessboard :

\documentclass[pstricks,border=5pt]{standalone}
\usepackage{pst-solides3d}

\begin{document}
\psset{Decran=15,viewpoint=20 -60 0 rtp2xyz}
\begin{pspicture}(-1,-2)(7,2)
\pstVerb{ /Element 0 store }
\psSolid[object=cylindrecreux,h=8,r=1.5,RotY=90,ngrid=8 8,
  fcol= 32 {
    Element (black) /Element Element 2 add store    
    Element 8 mod 0 eq 
      { /Element Element 1 add store } 
      { Element 8 mod 1 eq { /Element Element 1 sub store } if } ifelse } repeat
]
\end{pspicture}
\end{document}

enter image description here

  • Herbet- How do I change the number of square (home of the Board), for example, to 8 for 8 (usual chessboard)? – benedito Feb 3 '15 at 18:18
  • ngrid= 8 8. But then you have to modify the color setting, you'll get the number of the faces with num=all – user2478 Feb 3 '15 at 18:50
  • Heiko Oberdiek- I haven't given up. I really like your drawing that I'm still trying to get it here. – benedito Feb 7 '15 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.