9

For bw printing, I'd like to rotate the filling pattern. How to do this ?

enter image description here

\documentclass[margin=2pt]{standalone}
\usepackage{tikz,siunitx}
\usetikzlibrary{%
    calc,
    intersections,
    patterns}

\begin{document}
\hfill\begin{tikzpicture}[%
    every node/.style={font=\small}]

\def\X{3.5}

\coordinate (A) at (90:\X) ;
\coordinate (B) at (210:\X) ;
\coordinate (C) at (-30:\X) ;

\coordinate (I) at ($(A)!.5!(B)$) ;
\coordinate (J) at ($(A)!.5!(C)$) ;
\coordinate (K) at ($(C)!.5!(B)$) ;
\coordinate (E) at ($(B)!.5!(K)$) ;
\coordinate (F) at ($(C)!.5!(K)$) ;

\coordinate (N) at ($(E)!(F)!(J)$) ;
\coordinate (M) at ($(E)!(I)!(J)$) ;

\coordinate (N') at ($(N)!2!(J)$) ;
\coordinate (F') at ($(F)!2!(J)$) ;
\coordinate (M') at ($(M)!2!(I)$) ;
\coordinate (E') at ($(E)!2!(I)$) ;

\begin{scope}
\clip (0,0) rectangle (0,0) ;

\draw[name path=P1] (N')--($(N')!3!(F')$) ;
\draw[name path=P2] (M')--($(M')!3!(E')$) ;

\path[name intersections={%
    of= P1 and P2,  % nom des paths
    by=D,           % nom des points
    sort by=P1,     % suivant le path
    total=\t}]      % nb de points
\pgfextra{\xdef\InterNb{\t} } ;

\end{scope}

\fill[pattern=checkerboard light gray] (M)--(I)--(A)--(J)--cycle ;

\path[pattern=horizontal lines light blue] (E)--(M)--(I)--(B)--cycle;
\path[pattern=horizontal lines light blue] (E')--(M')--(I)--(A)--cycle;

\path[pattern=horizontal lines light gray] (F)--(N)--(J)--(C)--cycle;
\path[pattern=horizontal lines light gray] (F')--(N')--(J)--(A)--cycle;

%\draw pic[%
%   "\SI{71}{\degree}",
%   draw,
%   fill=blue!15,
%   angle eccentricity=1.4,
%   angle radius=.7cm
%   ] {angle=B--I--M} ;

%\draw pic[%
%   "\SI{131}{\degree}",
%   draw,
%   fill=blue!15,
%   angle eccentricity=1.5,
%   angle radius=.6cm
%   ] {angle=C--F--N} ;

%\draw pic[%
%   "\SI{101}{\degree}",
%   draw,
%   fill=blue!15,
%   angle eccentricity=1.7,
%   angle radius=.6cm
%   ] {angle=A--J--E} ;


\draw (A)--(B)--(C)--cycle ;
\draw (J)--(E) ;
\draw (I)--(M) ;
\draw (F)--(N) ;

\draw (F')--(E') ;
\draw[thick] (M)--(N')--(D)--(M')--cycle ;

\foreach \Coor/\Text/\Pos in 
    {A/$A$/90,
    B/$B$/-135,
    C/$C$/-45,
    E/$E$/-90,
    F/$F$/-90,
    I/$I$/180,
    J/$J$/0,
    M/$M$/-80,
    N/$N$/100%
    } {%
%   \path (\Coor) pic {Cross={2 and black}} ;
    %\node[small dot] at (\Coor) {} ;
    \node[shift=(\Pos:8pt),anchor=center] at (\Coor) {\Text} ;
    }

\end{tikzpicture}\hfill\strut
\end{document}

3 Answers 3

7

As bmv already answered, it's not possible to rotate a pattern, but it's not too difficult to define new rotated patterns.

Information about it can be found in section 104 Patterns and already defined styles can be found in file pgflibrarypatterns.code.tex.

Based on checkerboard light gray and horizontal lines light gray I've defined rotated checkerboard light gray and vertical lines light gray. The code can be found in following lines:

\documentclass[margin=2pt]{standalone}
\usepackage{tikz,siunitx}
\usetikzlibrary{%
    calc,
    intersections,
    patterns}

\pgfdeclarepatterninherentlycolored{rotated checkerboard light gray}
{\pgfpointorigin}{\pgfqpoint{4mm}{4mm}}{\pgfqpoint{4mm}{4mm}}%
{
  \pgfsetfillcolor{black!10}
  \pgfpathrectangle{\pgfpointorigin}{\pgfqpoint{4.1mm}{4.1mm}}% make
                                % slightly larger to ensure that tiles
                                % are really solid
  \pgfusepath{fill}
  \pgfsetfillcolor{black!20}
  \pgfpathmoveto{\pgfqpoint{0mm}{2mm}}
  \pgfpathlineto{\pgfqpoint{2mm}{4mm}}
  \pgfpathlineto{\pgfqpoint{4mm}{2mm}}
  \pgfpathlineto{\pgfqpoint{2mm}{0mm}}
  \pgfpathlineto{\pgfqpoint{0mm}{2mm}}
  \pgfusepath{fill}
}

\pgfdeclarepatterninherentlycolored{vertical lines light gray}
{\pgfpointorigin}{\pgfpoint{4pt}{100pt}}
{\pgfpoint{4pt}{100pt}}
{
  \pgfsetfillcolor{black!10}
  \pgfpathrectangle{\pgfpointorigin}{\pgfpoint{2.5pt}{100pt}}
  \pgfusepath{fill}
  \pgfsetfillcolor{black!15}
  \pgfpathrectangle{\pgfpoint{2pt}{0pt}}{\pgfpoint{2.5pt}{100pt}}
  \pgfusepath{fill}
}

\begin{document}
\hfill\begin{tikzpicture}[%
    every node/.style={font=\small}]

\def\X{3.5}

\coordinate (A) at (90:\X) ;
\coordinate (B) at (210:\X) ;
\coordinate (C) at (-30:\X) ;

\coordinate (I) at ($(A)!.5!(B)$) ;
\coordinate (J) at ($(A)!.5!(C)$) ;
\coordinate (K) at ($(C)!.5!(B)$) ;
\coordinate (E) at ($(B)!.5!(K)$) ;
\coordinate (F) at ($(C)!.5!(K)$) ;

\coordinate (N) at ($(E)!(F)!(J)$) ;
\coordinate (M) at ($(E)!(I)!(J)$) ;

\coordinate (N') at ($(N)!2!(J)$) ;
\coordinate (F') at ($(F)!2!(J)$) ;
\coordinate (M') at ($(M)!2!(I)$) ;
\coordinate (E') at ($(E)!2!(I)$) ;

\begin{scope}
\clip (0,0) rectangle (0,0) ;

\draw[name path=P1] (N')--($(N')!3!(F')$) ;
\draw[name path=P2] (M')--($(M')!3!(E')$) ;

\path[name intersections={%
    of= P1 and P2,  % nom des paths
    by=D,           % nom des points
    sort by=P1,     % suivant le path
    total=\t}]      % nb de points
\pgfextra{\xdef\InterNb{\t} } ;

\end{scope}

\fill[pattern=rotated checkerboard light gray] (M)--(I)--(A)--(J)--cycle ;

\path[pattern=horizontal lines light blue] (E)--(M)--(I)--(B)--cycle;
\path[pattern=horizontal lines light blue] (E')--(M')--(I)--(A)--cycle;

\path[pattern=vertical lines light gray] (F)--(N)--(J)--(C)--cycle;
\path[pattern=horizontal lines light gray] (F')--(N')--(J)--(A)--cycle;

%\draw pic[%
%   "\SI{71}{\degree}",
%   draw,
%   fill=blue!15,
%   angle eccentricity=1.4,
%   angle radius=.7cm
%   ] {angle=B--I--M} ;

%\draw pic[%
%   "\SI{131}{\degree}",
%   draw,
%   fill=blue!15,
%   angle eccentricity=1.5,
%   angle radius=.6cm
%   ] {angle=C--F--N} ;

%\draw pic[%
%   "\SI{101}{\degree}",
%   draw,
%   fill=blue!15,
%   angle eccentricity=1.7,
%   angle radius=.6cm
%   ] {angle=A--J--E} ;


\draw (A)--(B)--(C)--cycle ;
\draw (J)--(E) ;
\draw (I)--(M) ;
\draw (F)--(N) ;

\draw (F')--(E') ;
\draw[thick] (M)--(N')--(D)--(M')--cycle ;

\foreach \Coor/\Text/\Pos in 
    {A/$A$/90,
    B/$B$/-135,
    C/$C$/-45,
    E/$E$/-90,
    F/$F$/-90,
    I/$I$/180,
    J/$J$/0,
    M/$M$/-80,
    N/$N$/100%
    } {%
%   \path (\Coor) pic {Cross={2 and black}} ;
    %\node[small dot] at (\Coor) {} ;
    \node[shift=(\Pos:8pt),anchor=center] at (\Coor) {\Text} ;
    }

\end{tikzpicture}\hfill\strut
\end{document}

enter image description here

Update

With patterns.meta library is possible to rotate a pattern and also define new patterns with TiKZ syntax instead of only pgf syntax.

Following code shows the previous answer adapted to patterns.meta library. Main changes are the use of parametric Lines pattern and an example of tikzdeclarepattern applied to the rotated checkboard.

 \documentclass[margin=2pt]{standalone}
\usepackage{tikz,siunitx}
\usetikzlibrary{%
    calc,
    intersections,
    patterns.meta}

\tikzdeclarepattern{
    name = rotated checkboard,
    type=uncolored,
    parameters={\squaresize, \boardangle},
    bottom left={(-.1pt,-.1pt)},
    top right={(\squaresize+.1pt,\squaresize+.1pt)},
    tile size={(\squaresize,\squaresize)},
    tile transformation={rotate=\boardangle},
    defaults={
        tile size/.store in=\squaresize, tile size=10pt,
        rotate/.store in=\boardangle, rotate=0
    },
    code={
        \tikzset{x=1pt,y=1pt}
        \fill (0,0) rectangle (\squaresize/2,\squaresize/2);
        \fill (\squaresize/2,\squaresize/2) rectangle (\squaresize,\squaresize);
    }
}

\begin{document}
\hfill\begin{tikzpicture}[%
    every node/.style={font=\small}]

\def\X{3.5}

\coordinate (A) at (90:\X) ;
\coordinate (B) at (210:\X) ;
\coordinate (C) at (-30:\X) ;

\coordinate (I) at ($(A)!.5!(B)$) ;
\coordinate (J) at ($(A)!.5!(C)$) ;
\coordinate (K) at ($(C)!.5!(B)$) ;
\coordinate (E) at ($(B)!.5!(K)$) ;
\coordinate (F) at ($(C)!.5!(K)$) ;

\coordinate (N) at ($(E)!(F)!(J)$) ;
\coordinate (M) at ($(E)!(I)!(J)$) ;

\coordinate (N') at ($(N)!2!(J)$) ;
\coordinate (F') at ($(F)!2!(J)$) ;
\coordinate (M') at ($(M)!2!(I)$) ;
\coordinate (E') at ($(E)!2!(I)$) ;

\begin{scope}
\clip (0,0) rectangle (0,0) ;

\draw[name path=P1] (N')--($(N')!3!(F')$) ;
\draw[name path=P2] (M')--($(M')!3!(E')$) ;

\path[name intersections={%
    of= P1 and P2,  % nom des paths
    by=D,           % nom des points
    sort by=P1,     % suivant le path
    total=\t}]      % nb de points
\pgfextra{\xdef\InterNb{\t} } ;

\end{scope}

\fill[fill=orange!10, postaction={pattern={rotated checkboard[rotate=30, tile size=2mm]}, pattern color=orange}] (M)--(I)--(A)--(J)--cycle ;

\path[fill=cyan!20, postaction={pattern={Lines[angle=20, line width=2pt, distance=5pt]}, pattern color=cyan!70!black}] (E)--(M)--(I)--(B)--cycle;
\path[fill=red!30, postaction={pattern={Lines[angle=-35, line width=2pt, distance=6pt]}, pattern color=red!70!black}] (E')--(M')--(I)--(A)--cycle;

\path[fill=cyan!20, postaction={pattern={Lines[angle=90, line width=1pt, distance=3pt]}, pattern color=cyan!70!black}] (F)--(N)--(J)--(C)--cycle;
\path[fill=red!30, postaction={pattern={Lines[angle=85, line width=1pt, distance=3pt]}, pattern color=red!70!black}] (F')--(N')--(J)--(A)--cycle;

\draw (A)--(B)--(C)--cycle ;
\draw (J)--(E) ;
\draw (I)--(M) ;
\draw (F)--(N) ;

\draw (F')--(E') ;
\draw[thick] (M)--(N')--(D)--(M')--cycle ;

\foreach \Coor/\Text/\Pos in 
    {A/$A$/90,
    B/$B$/-135,
    C/$C$/-45,
    E/$E$/-90,
    F/$F$/-90,
    I/$I$/180,
    J/$J$/0,
    M/$M$/-80,
    N/$N$/100%
    } {%
%   \path (\Coor) pic {Cross={2 and black}} ;
    %\node[small dot] at (\Coor) {} ;
    \node[shift=(\Pos:8pt),anchor=center] at (\Coor) {\Text} ;
    }

\end{tikzpicture}
\end{document}

enter image description here

9

From TikZ & PGF Manual for Version 3.0.1a p. 171 (thanks to @Zarko)

Patterns are not overly flexible. In particular, it is not possible to change the size or orientation of a pattern without declaring a new pattern. For complicated case, it may be easier to use two nested \foreach statements to simulate a pattern, but patterns are rendered much more quickly than simulated ones.

3
  • but now is actual tikz v3.0.1a. in this is described on section 15.5.1 Graphic Parameters: Fill Pattern, page 171 ...
    – Zarko
    Feb 3, 2018 at 10:40
  • Which is the file that contains the definitions of this patterns, and where to find it ?
    – Tarass
    Feb 3, 2018 at 11:28
  • In my experience, it's a huge pain to even translate patterns. Feb 4, 2018 at 19:52
4

The figure is interesting: Dudeney's hinged dissection. Adding some code to change defaults of patterns library, or even recently patterns.meta library, is expensive, that increases complexity of the whole code. So I will draw a direct way.

I simplify OP's code, and using suitable \clip and \foreach to draw a check board (see here). The rotation angle JEC can be easily calculate via variable \patrot that is asin(sqrt(3/7)).

For black and white figure, just change colors.

enter image description here

\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{calc,patterns}
\begin{document}
\begin{tikzpicture}
\def\r{3.5}
\path 
(90:\r)  coordinate (A)
(210:\r) coordinate (B)
(-30:\r) coordinate (C)
(A)--(B) coordinate[midway] (I)
(A)--(C) coordinate[midway] (J)
(B)--(C) coordinate[pos=.25] (E) coordinate[pos=.75] (F)
($(E)!(F)!(J)$) coordinate (N)      
($(E)!(I)!(J)$) coordinate (M)
(M)--(I) coordinate[pos=2] (M')
(N)--(J) coordinate[pos=2] (N')
(E)--(I) coordinate[pos=2] (E')
(F)--(J) coordinate[pos=2] (F')
(intersection of N'--F' and M'--E') coordinate (D)
;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Way 1: uniform color      
%\fill[violet!30] (M)--(I)--(A)--(J)--cycle ;

% Way 2: using `patterns` library
%\path[pattern=checkerboard light gray] (M)--(I)--(A)--(J)--cycle ;

% Way 3: using \clip and \foreach  
\pgfmathsetmacro{\patrot}{asin(sqrt(3/7))} % rotation angle JEC
\begin{scope}
\clip (M)--(I)--(A)--(J)--cycle;
\begin{scope}[scale=.2,transform canvas={shift={(M)},rotate=\patrot}]
\def\n{15}
\foreach \i in {0,...,\n}
\foreach \j in {0,...,\n}
{
    \pgfmathparse{mod(\i+\n-\j,2) ? "red" : "white"}
    \fill[\pgfmathresult] (\i,\j) rectangle +(1,1);
}
\end{scope}
\end{scope}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\fill[green!30] (E)--(M)--(I)--(B)--cycle (E')--(M')--(I)--(A)--cycle;
\fill[cyan!30] (F)--(N)--(J)--(C)--cycle (F')--(N')--(J)--(A)--cycle;
\fill[yellow!30] (E)--(N)--(F)--cycle (E')--(D)--(F')--cycle;
\draw (J)--(E) (I)--(M) (F)--(N) (F')--(E') ;
\draw[thick] (A)--(B)--(C)--cycle (M)--(N')--(D)--(M')--cycle ;
        
\foreach \Coor/\Pos in {A/90,B/-135,C/-45,D/90,E/-90,E'/135,F/-90,F'/30,I/180,J/0,M/-80,M'/180,N/0,N'/0}
\path (\Coor)+(\Pos:.3) node{$\Coor$};
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .