# Insulation hatch

In civil engineering insulation hatch looks like this:

I did all the math to re-create such hatch and I attach MWE below.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}[]
\def\step{1}
\def\thic{2.5}
\pgfmathsetmacro{\rati}{\thic/\step-1}
\pgfmathsetmacro{\leng}{sqrt((\rati)^2-0.75)}
\pgfmathsetmacro{\angl}{90-atan((\leng+1/(2*\rati))/(1-\leng/(2*\rati)))}

\foreach \i in {0,...,9}{\draw (2*\i*\segmentlength,\amplitude) arc (90:-\angl:\segmentlength) -- ++(-90-\angl:2*\segmentlength*\leng) arc (180-\angl:360+\angl:\segmentlength) -- ++(90+\angl:2*\segmentlength*\leng) arc (180+\angl:90:\segmentlength);}
\draw (0,-\amplitude) rectangle (20*\segmentlength,\amplitude);    \draw (0,-0.5*\thic) rectangle (10,0.5*\thic);

\end{tikzpicture}
\end{document}


My question is: is it possible to automate this process? Say, you specify rectangle (which can be either vertical or horizontal), thickness to step ratio and then TikZ creates all by itself. Nasty possibilities are, that number of curves is not natural number, or trapezium is specified instead of rectangle. What would be most tikz-ish way to do that?

COMMENT: I have accepted Mark Wibrow's answer as it completely answers to my question, however I use modified percusse's answer because I need hatch in arbitrary direction.

• You could clip the result to the desired size/shape. That way, you'd actually potentially 'draw' more curves than you need but you'd clip the excess. Would that solve the non-natural number/trapezium issues? – cfr Nov 7 '14 at 22:28
• Note that it is not clear to me, at least, what is supposed to vary with what. What exactly is calculated? (Why 0.75, for example?) What criteria do the curves need to satisfy? Can you just calculate the curves to fit into the rectangle? – cfr Nov 7 '14 at 22:58
• It is not clear what you are asking. Do you want to define a pattern? That is pretty straightforward using \pgfdeclarepatternformonly. Or you want to do this manually but you are concerned about skewing/stretching the pattern to fill the rectangle? Should it always be one row of this pattern? Please specify a little bit... – Pouya Nov 8 '14 at 0:36
• @cfr Clipping will be fine (if no other solution provided). After some thinking, the user should provide non-dimensional ratio (\rati) and dimensional thickness (\thic). The rest is calculated by the pattern creator. – Pygmalion Nov 8 '14 at 15:59
• @Pouya I think pattern is not a good idea. First of all this pattern should be working both horizontally and vertically, and second, pattern should fit perfectly to the box. PDF patterns have life of its own and are fitted against the page margins instead of objects. – Pygmalion Nov 8 '14 at 16:00

You could try a path picture. Although I have completely ignored the OPs calculations and just gone for an insulation hatch that "sort-of" looks like the required pattern, the following illustrates how the approach could be used:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc}
\newif\iftikzhatchvertical
\tikzset{insulation hatch fill/.style={path picture={
\path [insulation hatch/.try]
[shift={(current path bounding box.south west)}]
\pgfextra{%
\pgfpointdiff{\pgfpointanchor{current path bounding box}{south west}}%
{\pgfpointanchor{current path bounding box}{north east}}%
\pgfgetlastxy\w\h%
\iftikzhatchvertical%
\let\tmp=\w\let\w=\h\let\h=\tmp%
\tikzset{xscale=-1,rotate=90}%
\fi%
\pgfmathsetlengthmacro\s{#1}%
\pgfmathparse{int(\w/\s+1)}\let\k=\pgfmathresult%
}
(0,\h)
\foreach \i in {0,...,\k} {
arc (90:0:\s/2) .. controls ++(270:\h/4) and ++(90:\h/4) .. (\i*\s, \s/2)
arc (180:360:\s/2) .. controls ++(90:\h/4) and ++(270:\h/4) .. (\i*\s+\s/2,\h-\s/2)
arc (180:90:\s/2) };
}
},
insulation hatch fill/.default=5mm,
vertical hatch/.is if=tikzhatchvertical
}

\begin{document}
\begin{tikzpicture}
\draw [insulation hatch/.style={draw=black}, insulation hatch fill]
(0,0) rectangle ++(5,2);
\draw [insulation hatch/.style={draw=gray, vertical hatch}, insulation hatch fill=7.5mm]
(0,3) rectangle ++(2,5);
\draw [minimum width=5cm,insulation hatch/.style={draw=black, thick}, insulation hatch fill=2.5mm]
(3,3) -- ++(1,1) -- ++(4,0) -- ++(-1,-1) -- cycle;
\draw [minimum width=5cm,insulation hatch/.style={draw=gray, thick, vertical hatch}, insulation hatch fill=2.5mm]
\end{tikzpicture}
\end{document}


• This took my breath away! Actually this looks reasonably similar to my example. Since there is no prescribed way to create this hatch, your result is probably as correct as mine. But can it be turned vertically? – Pygmalion Nov 8 '14 at 20:05
• @Pygmalion see the updated answer. – Mark Wibrow Nov 9 '14 at 8:31

A decoration might serve here but I didn't try to fit exact number of patterns. So if the path is not, sort of, a multiple of half-pattern length it just skips whatever remaining path. As usual with decorations, playing with the parameters leads to bonus features.

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations}
\pgfdeclaredecoration{insuline}{z}{%
\state{z}[width=\pgfdecorationsegmentlength,next state=s,switch if less than=\pgfdecorationsegmentlength to final]{%
\pgfpathmoveto{\pgfpoint{0pt}{.5\pgfdecorationsegmentamplitude}}%
\pgfpatharc{90}{0}{\pgfdecorationsegmentlength}%
\pgfpathlineto{\pgfpoint{0pt}{-.5\pgfdecorationsegmentamplitude+\pgfdecorationsegmentlength}}%
\pgfpatharc{180}{270}{\pgfdecorationsegmentlength}%
}%
\state{s}[width=\pgfdecorationsegmentlength,next state=z,switch if less than=\pgfdecorationsegmentlength to final]{%
\pgfpatharc{270}{360}{\pgfdecorationsegmentlength}%
\pgfpathlineto{\pgfpoint{0pt}{.5\pgfdecorationsegmentamplitude-\pgfdecorationsegmentlength}}%
\pgfpatharc{180}{90}{\pgfdecorationsegmentlength}%
}%
\state{final}{\pgfpathmoveto{\pgfpointorigin}}%
}

\begin{tikzpicture}
\draw[red,decorate,decoration={insuline,amplitude=1cm,segment length=3.5mm}] (0,0) -- (5.7,0);
\draw[blue,decorate,decoration={insuline,amplitude=2cm,segment length=1.5mm}] (0,2) -- (5.7,2);
\draw[green,decorate,decoration={insuline,amplitude=0.5cm,segment length=5mm}] (0,5) -- (5.7,5);
\draw[black,decorate,decoration={insuline,amplitude=-1cm,segment length=5mm}] (0,4) -- (5.7,4);
\end{tikzpicture}
\end{document}


• @Pygmalion I don't understand what your pattern is doing. Use TikZ syntax no PGF stuff, I mean \draw ... arc ... ++(angle:dist)... etc. Also just use the blue curve and change the segment length to 3 mm and it looks almost exactly what you have in the question. So I think you are confusing yourself a bit. – percusse Nov 8 '14 at 21:38
• @Pygmalion Do the math inside persistent precomputation block and they would be available in the body of the state. – percusse Nov 9 '14 at 10:43
• Thanks. That solved the problem! The pattern is working perfectly. – Pygmalion Nov 9 '14 at 13:30
• @Pygmalion Cool. Now we have one more person to answer decoration questions then ;) – percusse Nov 9 '14 at 13:55