# Rotate and clip shading in TikZ

I'm trying to produce a copy of the right hand side of this picture using TikZ shadings.

I thought it would be a simple task but it has proven itself difficult (at least for me).

First I couldn't find a way to make that kind of shading inclined by default, so I opted to make it straight and then rotate the outcome and then clip it. The thing is, when rotating the figure ends up in a werid spot of the document (not centered). So I don't know exactly how to produce both patterns, rotate them, clip them and then placing them one under the other.

This is what I managed to do until now:

\begin{figure}[!h]
\begin{tikzpicture}%[transform canvas={rotate=45}]
\pgflowlevelobj{\pgftransformrotate{45}}{
\foreach \i in {-3,...,3}
\end{tikzpicture}
\end{figure}


Taking advantage of what you've already done, but changing a little the coordinates; for the lower part I used a custom pattern which is a variation of north east lines, but allowing you to specify the separation between the lines, their width and color:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{patterns}

% defining the new dimensions and parameters
\newlength{\hatchthickness}
\newlength{\hatchshift}
\newcommand{\hatchcolor}{}
% declaring the keys in tikz
hatchthickness/.code={\setlength{\hatchthickness}{#1}},
hatchshift/.code={\setlength{\hatchshift}{#1}},% must be >= 0
hatchcolor/.code={\renewcommand{\hatchcolor}{#1}}}
% setting the default values
hatchthickness=0.4pt,
hatchshift=0pt,% must be >= 0
hatchcolor=black}
%\pgfdeclarepatternformonly{north east lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{4pt}{4pt}}{\pgfqpoint{3pt}{3pt}}%
%{
%  \pgfsetlinewidth{0.4pt}
%  \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
%  \pgfpathlineto{\pgfqpoint{3.1pt}{3.1pt}}
%  \pgfusepath{stroke}
%}

% declaring the pattern
{custom north east lines}% name
{\pgfqpoint{\dimexpr-2\hatchthickness}{\dimexpr-2\hatchthickness}}% lower left corner
{% shape description
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\ifdim \hatchshift > 0pt
\pgfpathmoveto{\pgfqpoint{0pt}{\hatchshift}}
\pgfpathlineto{\pgfqpoint{\dimexpr0.15pt+\hatchshift}{-0.15pt}}
\fi
\pgfsetstrokecolor{\hatchcolor}
%    \pgfsetdash{{1pt}{1pt}}{0pt}% dashing cannot work correctly in all situation this way
\pgfusepath{stroke}
}

\begin{document}

\centering
\begin{tikzpicture}
\begin{scope}
\clip
(-4,-1.7) -- (-4,1) -- (4,1) -- (4,-2) -- cycle;
\begin{scope}[transform canvas={rotate around={12.5:(3,0)}}]
\foreach \i in {-8,...,8}
{
}
\end{scope}
\end{scope}
\fill[gray!15]
(-4,-1.7) -- (-4,-5) -- (4,-5) -- (4,-2) -- cycle;
\fill[
pattern=custom north east lines,
hatchthickness=1.35pt,
hatchcolor=black!60,
]
(-4,-1.7) -- (-4,-5) -- (4,-5) -- (4,-2) -- cycle;
%Auxiliary grid
%\draw
%  (-5,-5) grid (5,1);
%\foreach \Valor in {-5,...,5}
%  \node[below] at (\Valor,-5) {\Valor};
\end{tikzpicture}

\end{document}


The definition for the new pattern was inspired by Philippe Goutet's answer to Custom and built in TikZ fill patterns.

• Whoa! Thanks for the speedy answer. That did the job wonderfully. Thanks!! To clarify, the lower part is also a shading pattern, just more compressed, but I was able to use what you'd given me and alter it to do the job. I'll post the final version as an answer. Aug 29 '15 at 1:36

To clarify, the lower part is also a shading pattern, just more compressed, but I was able to use what you'd given me and alter it to do the job.

\begin{figure}[!ht]
\begin{minipage}{0.5\linewidth}
\begin{tikzpicture}
\node[inner sep = 0] (a) at (-4,0) {\scalebox{-1}[1]{\includegraphics[height=2cm]{dish.png}}};
\node[inner sep = 0] (b) at (-2,0) {\scalebox{-1}[1]{\includegraphics[height=2cm]{dish.png}}};
\draw[<->] (a.south) -- node[below] {$\overrightarrow{b_1}$} (b.south) ;

\node[inner sep = 0] (a) at (-5,-5) {\scalebox{-1}[1]{\includegraphics[height=2cm]{dish.png}}};
\node[inner sep = 0] (b) at (-1,-5) {\scalebox{-1}[1]{\includegraphics[height=2cm]{dish.png}}};
\draw[<->] (a.south) -- node[below] {$\overrightarrow{b_2}$} (b.south);
\end{tikzpicture}
\end{minipage}
\begin{minipage}{0.5\linewidth}
\begin{tikzpicture}
\begin{scope}
\clip
(0,-9) -- (7,-9) -- (7,-12.5) -- (0,-12.5) -- cycle;
\pgflowlevelobj{\pgftransformrotate{12.5}}{
\foreach \i in {-8,...,8}
{
}
}
\end{scope}
\begin{scope}
\clip
(0,-12.5) -- (7,-12.5) -- (7,-16) -- (0,-16) -- cycle;
\pgflowlevelobj{\pgftransformrotate{-12.5}}{
\foreach \i in {0,...,55}
{