Changing density of pattern in TikZ
In his answer to Pgfplots: how to fill the area under a curve with oblique lines (hatching) as a pattern?, Jake defines a north east hatch
whit two parameters: hatch distance and hatch thickness. You can use this pattern and adjust these parameters to your taste.
Here you have an example:
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows,patterns}
%See https://tex.stackexchange.com/a/29367/1952
\makeatletter
\tikzset{% customization of pattern
hatch distance/.store in=\hatchdistance,
hatch distance=5pt,
hatch thickness/.store in=\hatchthickness,
hatch thickness=5pt
}
\pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{north east hatch}% name
{\pgfqpoint{-1pt}{-1pt}}% below left
{\pgfqpoint{\hatchdistance}{\hatchdistance}}% above right
{\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
{
\pgfsetcolor{\tikz@pattern@color}
\pgfsetlinewidth{\hatchthickness}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
\pgfusepath{stroke}
}
\makeatother
\begin{document}
\begin{tikzpicture}[>=stealth,every node/.style={font=\tiny}]
\draw[very thick] (0,5) -- (0,0) -- (5,0) -- (5,5);
\fill[pattern=north east lines,very thick] (0,4.98) -- (0,0) -- (5,0) -- (5,4.98);
\draw[very thick,fill=white] (.2,5) -- (.2,.2) -- (4.8,.2) -- (4.8,5);
\draw[very thick] (.2,1) -- (4.8,1);
\draw[very thick] (.4,5) -- (.4,1) -- (4.6,1) -- (4.6,5) to[bend left=30] (2.5,5) to[bend right=30] (.4,5) -- cycle;
\draw[very thick] (4.6,5) to[bend right=30] (2.5,5);
\pattern[pattern=north east hatch, hatch distance=3mm, hatch thickness=.5pt] (2.5,5) to[bend right=30] (4.6,5) to[bend right=30] (2.5,5) -- cycle;
\pattern[pattern=north east hatch, hatch distance=1mm, hatch thickness=.5pt] (.4,1.2) -- (4.6,1.2) -- (4.6,1) -- (.4,1) -- cycle;
\draw[very thick] (.4,1.2) -- (4.6,1.2);
\draw[very thick,fill=white] (2.2,.9) rectangle (2.8,1.3);
\draw (2.2,1) -- (2.8,1);
\draw (2.2,1.2) -- (2.8,1.2);
\draw[ultra thin,dash pattern={on 5pt off 2pt on 1pt off 3pt}] (2.5,.5) --+ (0,5);
\draw[<->] (.4,3.7) -- (4.6,3.7) node[midway,fill=white] {$\stackrel{d_a}{(2r_a)}$};
\draw[ultra thick,<-] (2.5,5) --+ (0,2) node[left] {$P$};
\draw (2.2,.9) --+ (0,-1.5);
\draw (2.8,.9) --+ (0,-1.5);
\draw[thick,<-] (2.2,-.4) --+ (-.7,0);
\draw[thick,<-] (2.8,-.4) --+ (.7,0);
\node[below=2] at (2.5,0) {$d_i$};
\end{tikzpicture}
\end{document}
Warning: This is not an answer, there are still things that need to get fixed. But this might be a starting point. If somebody else completes this in the meantime, I will be happy to delete this post. What I did was to copy some of the patterns from the pgf library patterns and started to make them more flexible. This works, to some extent.
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows,patterns}
\makeatletter
\newlength{\flex@pattern@density}
\newlength{\flex@pattern@linewidth}
\newlength{\flex@pattern@auxlength}
\newlength{\flex@pattern@auxlengthtwo}
\tikzset{/tikz/.cd,
pattern density/.code={\setlength\flex@pattern@density{#1}
\pgfmathsetmacro{\tmp}{1.1*#1}
\setlength\flex@pattern@auxlength{\tmp pt}
\setlength\flex@pattern@auxlengthtwo{#1}
\advance\flex@pattern@auxlengthtwo by 0.1pt
\typeout{\the\flex@pattern@density,\the\flex@pattern@auxlength}},
pattern density=3pt,
pattern line width/.code={\setlength\flex@pattern@linewidth{#1}},
pattern line width=0.4pt,
}
\pgfdeclarepatternformonly[\flex@pattern@density,\flex@pattern@linewidth]{flexible horizontal lines}{\pgfpointorigin}{\pgfqpoint{100pt}{1pt}}{\pgfqpoint{100pt}{\flex@pattern@density}}%
{
\pgfsetlinewidth{\flex@pattern@linewidth}
\pgfsetcolor{\tikz@pattern@color}
\pgfpathmoveto{\pgfqpoint{0pt}{0.5pt}}
\pgfpathlineto{\pgfqpoint{100pt}{0.5pt}}
\pgfusepath{stroke}
}
\pgfdeclarepatternformonly[\flex@pattern@density,\flex@pattern@linewidth]{flexible vertical lines}{\pgfpointorigin}{\pgfqpoint{1pt}{100pt}}{\pgfqpoint{\flex@pattern@density}{100pt}}%
{
\pgfsetlinewidth{\flex@pattern@linewidth}
\pgfsetcolor{\tikz@pattern@color}
\pgfpathmoveto{\pgfqpoint{0.5pt}{0pt}}
\pgfpathlineto{\pgfqpoint{0.5pt}{100pt}}
\pgfusepath{stroke}
}
\pgfdeclarepatternformonly[\flex@pattern@auxlengthtwo,\flex@pattern@density,\flex@pattern@linewidth,\flex@pattern@auxlength]{flexible north east lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\flex@pattern@auxlength}{\flex@pattern@auxlength}}{\pgfqpoint{\flex@pattern@density}{\flex@pattern@density}}%
{
\pgfsetlinewidth{\flex@pattern@linewidth}
\pgfsetcolor{\tikz@pattern@color}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\flex@pattern@auxlengthtwo}{\flex@pattern@auxlengthtwo}}
\pgfusepath{stroke}
}
\pgfdeclarepatternformonly[\flex@pattern@auxlengthtwo,\flex@pattern@density,\flex@pattern@linewidth,\flex@pattern@auxlength]{flexible north west lines}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\flex@pattern@auxlength}{\flex@pattern@auxlength}}{\pgfqpoint{\flex@pattern@density}{\flex@pattern@density}}%
{
\pgfsetlinewidth{\flex@pattern@linewidth}
\pgfsetcolor{\tikz@pattern@color}
\pgfpathmoveto{\pgfqpoint{\flex@pattern@auxlengthtwo}{0pt}}
\pgfpathlineto{\pgfqpoint{0pt}{\flex@pattern@auxlengthtwo}}
\pgfusepath{stroke}
}
% Crossed lines in different directions
\pgfdeclarepatternformonly[\flex@pattern@density,\flex@pattern@linewidth,\flex@pattern@auxlength,\tikz@pattern@color]{flexible grid}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\flex@pattern@auxlength}{\flex@pattern@auxlength}}{\pgfqpoint{\flex@pattern@density}{\flex@pattern@density}}%
{
\pgfsetlinewidth{\flex@pattern@linewidth}
\pgfsetcolor{\tikz@pattern@color}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{0pt}{\flex@pattern@density}}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\flex@pattern@density}{0pt}}
\pgfusepath{stroke}
}
\pgfdeclarepatternformonly[\flex@pattern@density,\flex@pattern@linewidth,\flex@pattern@auxlength,\tikz@pattern@color]{flexible crosshatch}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{\flex@pattern@auxlength}{\flex@pattern@auxlength}}{\pgfqpoint{3pt}{3pt}}%
{
\pgfsetlinewidth{\flex@pattern@linewidth}
\pgfsetcolor{\tikz@pattern@color}
\pgfpathmoveto{\pgfqpoint{\flex@pattern@density}{0pt}}
\pgfpathlineto{\pgfqpoint{0pt}{\flex@pattern@density}}
\pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
\pgfpathlineto{\pgfqpoint{\flex@pattern@density}{\flex@pattern@density}}
\pgfusepath{stroke}
}
% Dotted regions
\pgfdeclarepatternformonly[\flex@pattern@density,\flex@pattern@linewidth,\tikz@pattern@color]{flexible dots}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{1pt}{1pt}}{\pgfqpoint{\flex@pattern@density}{\flex@pattern@density}}%
{
\pgfsetcolor{\tikz@pattern@color}
\pgfpathcircle{\pgfqpoint{0pt}{0pt}}{\flex@pattern@linewidth}
\pgfusepath{fill}
}
\pgfdeclarepatternformonly[\flex@pattern@density,\flex@pattern@linewidth,\tikz@pattern@color]{flexible crosshatch dots}{\pgfqpoint{-1pt}{-1pt}}{\pgfqpoint{2.5pt}{2.5pt}}{\pgfqpoint{\flex@pattern@density}{\flex@pattern@density}}%
{
\pgfsetcolor{\tikz@pattern@color}
\pgfpathcircle{\pgfqpoint{0pt}{0pt}}{\flex@pattern@linewidth}
\pgfpathcircle{\pgfqpoint{1.5pt}{1.5pt}}{\flex@pattern@linewidth}
\pgfusepath{fill}
}
\makeatother
\begin{document}
\begin{tikzpicture}[>=stealth,every node/.style={font=\tiny}]
\draw[very thick] (0,5) -- (0,0) -- (5,0) -- (5,5);
\fill[pattern=flexible north east lines,pattern line
width=0.8pt,pattern color=blue] (0,4.98) -- (0,0) -- (5,0) -- (5,4.98);
\draw[very thick,fill=white] (.2,5) -- (.2,.2) -- (4.8,.2) -- (4.8,5);
\draw[very thick] (.2,1) -- (4.8,1);
\draw[very thick] (.4,5) -- (.4,1) -- (4.6,1) -- (4.6,5) to[bend left=30] (2.5,5) to[bend right=30] (.4,5) -- cycle;
\draw[very thick] (4.6,5) to[bend right=30] (2.5,5);
\begin{scope}
\draw[pattern=flexible north west lines,pattern density=9pt] (2.5,5) to[bend right=30] (4.6,5) to[bend right=30] (2.5,5) -- cycle;
% \foreach \x in {1,2,...,14}
% {
% \draw[xshift=4.5cm,yshift=5cm,xshift=-2cm,xshift=4*\x] (120:1) -- (-60:1);
% }
\end{scope}
\fill[pattern=north west lines] (2.5,5) to[bend right=30] (4.6,5) to[bend right=30] (2.55,5) -- cycle;
\begin{scope}
\draw[pattern=flexible north east lines,pattern color=red,
pattern density=1pt,pattern line width=0.2pt] (.4,1.2) -- (4.6,1.2) -- (4.6,1) -- (.4,1) -- cycle;
\end{scope}
\draw[very thick] (.4,1.2) -- (4.6,1.2);
\draw[very thick,fill=white] (2.2,.9) rectangle (2.8,1.3);
\draw (2.2,1) -- (2.8,1);
\draw (2.2,1.2) -- (2.8,1.2);
\draw[ultra thin,dash pattern={on 5pt off 2pt on 1pt off 3pt}] (2.5,.5) --+ (0,5);
\draw[<->] (.4,3.7) -- (4.6,3.7) node[midway,fill=white] {$\stackrel{d_a}{(2r_a)}$};
\draw[ultra thick,<-] (2.5,5) --+ (0,2) node[left] {$P$};
\draw (2.2,.9) --+ (0,-1.5);
\draw (2.8,.9) --+ (0,-1.5);
\draw[thick,<-] (2.2,-.4) --+ (-.7,0);
\draw[thick,<-] (2.8,-.4) --+ (.7,0);
\node[below=2] at (2.5,0) {$d_i$};
\end{tikzpicture}
\end{document}
The colors are just for fun, I was using Ignasis answer, and really could not make sense of the comment below it but may well be missing something.
There are several things that do not work or I am not sure about.
If I choose the
pattern density
to be8pt
instead of9pt
, the lines are no longer equidistant. Most likely there is something obvious I am missing, but it is late here and I don't see it.Not sure if
pattern density
is a good name for that distance.Can't make the
pattern density
very small either.Only started to test the
flexible north west lines
andflexible north east lines
, not the others.