我可以画出圆柱体:
\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}
但是,我甚至无法在圆柱体的侧面区域画出棋盘,如下图所示
答案1
以下解决方案使用plot
命令绘制曲线。通过在水平和垂直方向上绘制每个第二个条纹并进行even odd rule
填充来创建棋盘状区域。
\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}
对评论的备注,缺少分号。我无法使用下面发布的版本重现此错误消息。\fill
命令包含二 \foreach
循环,用于水平和垂直条纹,否则使用 的技巧even odd rule
将不起作用。因此,\fill
命令的分号位于第 49 行,就在结束 之前\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
***********
答案2
使用xelatex
或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}
对于 8x8 棋盘来说也是一样:
\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}