# How to use composite Tikz pics with rotation

I am trying to draw a tiled pattern, building it from simpler elements using pic.

This is a simplified version of my code

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}

\begin{document}

\tikzset{
one/.pic = {
\draw [thin,blue] (0,0) -- (1,0) -- (1,1) -- cycle;
\draw [red] (1,0) -- ({1/(2+sqrt(2)},{1/(2+sqrt(2)});
},
two/.pic = {
\path pic {one} pic[rotate=90,yscale=-1] {one};
}
}

\begin{tikzpicture}
% pic one
\path pic {one} ;
\end{tikzpicture}

\begin{tikzpicture}
% pic two
\path pic {two} ;
\end{tikzpicture}

\begin{tikzpicture}
% pic two
\path pic {one} pic[rotate=90,yscale=-1] {one};
% pic two with extra 90 degree rotation
\path pic [rotate=90] {one} pic[rotate=180,yscale=-1] {one};
\end{tikzpicture}

\begin{tikzpicture}
% pic two
\path pic {two};
% pic two with extra 90 degree rotation
\path pic[rotate=90] {two};
% this doesn't do what I expected
\end{tikzpicture}

\end{document}


It draws four pictures. The first is the basic element.

The second is a rotation and reflection of the basic element drawn using a second pic element that uses the first

The third uses just the first pic element to draw two copies of the second pic element with one rotated by 90 degree.

The fourth tries to do the same thing, by using the second pic and rotating it by 90 degrees.

Why does it not work? How can I draw a rotated version of pic {two}? Is there a better way of doing this?

(I am actually trying to draw a more complicated pattern; this is a simplified version.)

This is a version of the final "pattern" I am trying to make. It's not a Tikz "pattern" in the sense of a fill, although I suppose it could be (sorry for the confusion). It's a geometric pattern based on Islamic design principles. Here is the original.

If you want to transform pics nested in another pic, you need to add transform shape. If one adds that key, one gets

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}

\begin{document}

\tikzset{
one/.pic = {
\draw [thin,blue] (0,0) -- (1,0) -- (1,1) -- cycle;
\draw [red] (1,0) -- ({1/(2+sqrt(2)},{1/(2+sqrt(2)});
},
two/.pic = {
\path pic {one} pic[rotate=90,yscale=-1] {one};
}
}

\begin{tikzpicture}
% pic one
\path pic {one} ;
\end{tikzpicture}

\begin{tikzpicture}
% pic two
\path pic {two} ;
\end{tikzpicture}

\begin{tikzpicture}
% pic two
\path pic {one} pic[rotate=90,yscale=-1] {one};
% pic two with extra 90 degree rotation
\path pic [rotate=90] {one} pic[rotate=180,yscale=-1] {one};
\end{tikzpicture}

\begin{tikzpicture}
% pic two
\path pic {two};
% pic two with extra 90 degree rotation
\path[transform shape] pic[rotate=90] {two};
% this doesn't do what I expected
\end{tikzpicture}

\end{document}


Since you want to design a pattern: are you aware of the patterns.meta library, whose documentation got recently added to the pgfmanual? This may be the easier way to go.

• Thank you. That's what I was looking for. But why don't I need a [transform shape] in the definition of two/.pic? It transforms a pic which is nested too. – pheon Nov 10 '19 at 19:13
• @pheon You explicitly spell out the transformation of the one pic inside the two pic. This is different from adding an ambient (is this wording appropriate here?) transformation. – user194703 Nov 10 '19 at 20:28
• Do you know if nesting pics is safe? I had the idea it wasn't, but can't remember why. – cfr Nov 11 '19 at 0:08
• @cfr I can’t really guarantee that it always works, but I have done it several times and never encountered problems. Of course, you need to make sure that you use ‘pic actions’ and ‘transform shape’ appropriately. And if the OP wants to create a pattern, patterns.meta might be a better tool. – user194703 Nov 11 '19 at 0:54