我有以下最小示例:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{folding}
\begin{document}
\begin{tikzpicture}
\tikzfoldingdodecahedron[folding line length=2cm,face 1={\fill (0,0) circle (1.5cm);}];
\end{tikzpicture}
\end{document}
第一个面的圆对于五边形来说略大。有没有办法将圆剪裁到五边形?我尝试使用clip
,regular polygon
但没有成功。有什么建议吗?
答案1
您真的要剪辑吗?或者您想让整个多边形变黑?
面部轨迹
不管怎样,脸部的路径是
\path[
xshift=-.5\tikz@lib@fold@length,
yshift=-0.68819\tikz@lib@fold@length
] (0,0) -- ++ (0*72:\tikz@lib@fold@length)
-- ++ (1*72:\tikz@lib@fold@length)
-- ++ (2*72:\tikz@lib@fold@length)
-- ++ (3*72:\tikz@lib@fold@length)
-- cycle;
\tikz@lib@fold@length
由密钥设置的长度folding line length
定义为tikzlibraryfolding.code.tex
:
%
% Length of a standard line in a folding
%
\tikzoption{folding line length}{\pgfmathsetlength\tikz@lib@fold@length{#1}}
\newdimen\tikz@lib@fold@length
\tikz@lib@fold@length=2cm
\tikzfoldingpolygon[<opt arg>]
为了重新使用多边形的路径,我定义了一个用户宏\tikzfoldingpolygon[<opt arg>]
,它采用给予多边形路径的一个可选参数。
\newcommand*{\tikzfoldingpolygon}[1][clip]{
\path[
folding polygon shift,
#1
] (0,0) -- ++ (0*72:\tikz@lib@fold@length)
-- ++ (1*72:\tikz@lib@fold@length)
-- ++ (2*72:\tikz@lib@fold@length)
-- ++ (3*72:\tikz@lib@fold@length)
-- cycle;
}
样式folding polygon shift
(用于重复使用向面内左下角的移动)
\tikzset{
folding polygon shift/.style={
xshift=-.5\tikz@lib@fold@length,
yshift=-0.68819\tikz@lib@fold@length,
}
}
clip
可选参数的默认值是clip
,因此一个简单的
\tikzfoldingpolygon
足以剪辑所有后续操作。
fill
\tikzfoldingpolygon[fill=green]% overwrites clip
代码
\documentclass[tikz,border=5pt]{standalone}
\usetikzlibrary{folding}
\makeatletter
\tikzset{
folding polygon shift/.style={
xshift=-.5\tikz@lib@fold@length,
yshift=-0.68819\tikz@lib@fold@length,
}
}
\newcommand*{\tikzfoldingpolygon}[1][clip]{
\path[
folding polygon shift,
#1
] (0,0) -- ++ (0*72:\tikz@lib@fold@length)
-- ++ (1*72:\tikz@lib@fold@length)
-- ++ (2*72:\tikz@lib@fold@length)
-- ++ (3*72:\tikz@lib@fold@length)
-- cycle;
}
\makeatother
\begin{document}
\begin{tikzpicture}
\tikzfoldingdodecahedron[
folding line length=2cm,
face 1={% clipped
\tikzfoldingpolygon
\fill (0,0) circle (1.5cm);
},
face 2={
\tikzfoldingpolygon[fill=green]
},
face 12={
\tikzfoldingpolygon[]% empty optional argment overwrites default clip
\fill[red] (0,0) circle (1.5cm);
}
];
\end{tikzpicture}
\end{document}
输出
答案2
除了圆形,您还可以使用边长为 的多边形5
。
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{folding,shapes.geometric}
%
\begin{document}
%
\begin{tikzpicture}
\tikzfoldingdodecahedron[folding line length=2cm,face 1={\node[draw=none,fill,regular polygon,
regular polygon sides=5, inner sep=.97cm,opacity=1] at (0,0) {};}];
\end{tikzpicture}
%
\end{document}
但inner sep
必须手动调整才能正确填写:-(
。另外,我还添加了选项opacity=x
,作为个人喜好(您可以使用它来使事情变得更有趣)。