# Clipping using the folding library of tikz

I have the following minimal example:

\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}


The circle in the first face is slightly too big for the pentagon. Is there a way that the circles is clipped to the pentagon? I tried using clip and regular polygon but it did not work. Any suggestions?

-

Do you really want to clip or do you want the whole polygon black?

## Path of face

Either way, the path of the face is

\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;


The length \tikz@lib@fold@length which is set by the folding line length key is defined in 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>]

For the sake of re-using the polygon’s path, I defined a user macro \tikzfoldingpolygon[<opt arg>] which takes one optional argument that is given to the polygon’s path.

\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;
}


### The folding polygon shift style (for re-use of the shifting to the lower-left corner inside a face)

\tikzset{
folding polygon shift/.style={
xshift=-.5\tikz@lib@fold@length,
yshift=-0.68819\tikz@lib@fold@length,
}
}


### clip

The default for the optional argument is clip, so a simple

\tikzfoldingpolygon


suffices to clip all following operations.

### fill

\tikzfoldingpolygon[fill=green]% overwrites clip


## Code

\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}


## Output

-
Very nice tutorial. +1 –  hpesoj626 Dec 13 '12 at 7:19
This looks very good. I'll try it, thank you! EDIT: Tried it, worked flawlessly. Now I can make pretty pictured dodecahedrons. (Nice christmas gift) –  Wauzl Dec 13 '12 at 9:00

Instead of a circle, you can use a polygon of side 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}


But the inner sep has to be manually adjusted so as to fill in properly :-(. Also I have added the option opacity=x, as a personal taste (you may use it for making the thing more fancier).

-
The inner sep can be calculated by <folding line length>/2-2\pgflinewidth. Also, draw=none and draw? –  Qrrbrbirlbel Dec 13 '12 at 0:17
That's not really what I wanted. I really want to clip the circle, so there are some white areas left. –  Wauzl Dec 13 '12 at 9:00