1

I am trying to create a a grid of deformed hexagons in the y direction. The following solution given by @Ignasi seems okay for the undeformed case

Drawing hexagons

and after trying to modify the code, I am not able to get what I want, so I am thinking of the possibility of deforming the resulting tikz image.

Is there any command that I can use to achieve what I want?


\documentclass{article}

\usepackage{tikz} \usetikzlibrary{patterns}

\def\hexagonsize{0.5cm} \pgfdeclarepatternformonly {hexagons}% name {\pgfpointorigin}% lower left {\pgfpoint{3\hexagonsize}{0.8660252\hexagonsize}}% upper right {\pgfpoint{3\hexagonsize}{0.8660252\hexagonsize}}% tile size {% shape description \pgfsetlinewidth{0.4pt} \pgftransformshift{\pgfpoint{0mm}{0.866025\hexagonsize}} \pgfpathmoveto{\pgfpoint{0mm}{0mm}} \pgfpathlineto{\pgfpoint{0.5\hexagonsize}{0mm}} \pgfpathlineto{\pgfpoint{\hexagonsize}{-0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2\hexagonsize}{-0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2.5\hexagonsize}{0mm}} \pgfpathlineto{\pgfpoint{3\hexagonsize+0.2mm}{0mm}} \pgfpathmoveto{\pgfpoint{0.5\hexagonsize}{0mm}} \pgfpathlineto{\pgfpoint{\hexagonsize}{0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2\hexagonsize}{0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2.5\hexagonsize}{0mm}} \pgfusepath{stroke} } \begin{document}

\begin{tikzpicture} \fill[pattern=hexagons] (0,0) rectangle (5,5); \end{tikzpicture}

\end{document}

And what I want is to stretch the image in the vertical direction. For example, in terms of images, if this is a 100x100 image, I would like to convert it to a 100x200 image.

In regards to the code, the idea is to extend the length of the sides of the hexagon in the y direction, but I am not able to do it. I have tried to multiply the numbers by 2 or something like that, but I was not successful

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
Daniel8
  • 13
  • Welcome to TeX.SX! So, what did you try exactly? Could you provide some of your code? – Jasper Habicht Apr 09 '22 at 09:34
  • I guess that you like to scale image (make it bigger or smaller). Is this a case? If yes, add to tikzpicture option scale=<amount>. However, for better help you please provide a small but complete document with your image, that we see what you try so far. – Zarko Apr 09 '22 at 09:43
  • I elaborated my post in the answer below – Daniel8 Apr 09 '22 at 13:06
  • While [yscale=2] doubles the height of the rectangle, the shape of the hexagons doesn't change. You will need to modify the pattern itself. – John Kormylo Apr 09 '22 at 14:53

2 Answers2

1

Note that \pgftransformyscale{\hexscale} did not affect the other arguments.

\documentclass{standalone}

\usepackage{tikz} \usetikzlibrary{patterns}

\def\hexagonsize{0.5cm} \def\hexscale{2} \pgfdeclarepatternformonly {hexagons}% name {\pgfpointorigin}% lower left {\pgfpoint{3\hexagonsize}{0.8660252\hexagonsize\hexscale}}% upper right {\pgfpoint{3\hexagonsize}{0.8660252\hexagonsize\hexscale}}% tile size {% shape description \pgfsetlinewidth{0.4pt} \pgftransformyscale{\hexscale} \pgftransformshift{\pgfpoint{0mm}{0.866025\hexagonsize}} \pgfpathmoveto{\pgfpoint{0mm}{0mm}} \pgfpathlineto{\pgfpoint{0.5\hexagonsize}{0mm}} \pgfpathlineto{\pgfpoint{\hexagonsize}{-0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2\hexagonsize}{-0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2.5\hexagonsize}{0mm}} \pgfpathlineto{\pgfpoint{3\hexagonsize+0.2mm}{0mm}} \pgfpathmoveto{\pgfpoint{0.5\hexagonsize}{0mm}} \pgfpathlineto{\pgfpoint{\hexagonsize}{0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2\hexagonsize}{0.866025\hexagonsize}} \pgfpathlineto{\pgfpoint{2.5\hexagonsize}{0mm}} \pgfusepath{stroke} } \begin{document}

\begin{tikzpicture}[yscale=2] \fill[pattern=hexagons] (0,0) rectangle (5,5); \end{tikzpicture}

\end{document}

demo

John Kormylo
  • 79,712
  • 3
  • 50
  • 120
0

Here another way of compressing or stretching the hexagonal lattice:

\documentclass{standalone}        
\begin{tikzpicture}
   \def\t{1/2};
   \def\s{1};
  \foreach \i in {0,...,8}
  \foreach \j in {0,...,3} {
  \coordinate (P) at (3*\i*\t,2*sin{60}*\j*\s);
  \coordinate (Q) at ([shift={(3*\t/2,sin{60}*\s)}]P);
  \draw[blue,thick]
        (P) -- ([shift={(\t,0)}]P)
        (P) -- ([shift={(-\t/2,-sin{60}*\s)}]P)
        (P) -- ([shift={(-\t/2,+sin{60}*\s)}]P);
  \draw[blue,thick]
        (Q) -- ([shift={(\t,0)}]Q)
        (Q) -- ([shift={(-\t/2,-sin{60}*\s)}]Q)
        (Q) -- ([shift={(-\t/2,+sin{60}*\s)}]Q);
}
\end{tikzpicture}
\end{document}

or quite simply

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[xscale=1/2, yscale=1]
  \foreach \i in {0,...,8}
  \foreach \j in {0,...,3} {
  \coordinate (P) at (3*\i,2*sin{60}*\j);
  \coordinate (Q) at ([shift={(3/2,sin{60})}]P);
  \draw[blue,thick]
        (P) -- ([shift={(1,0)}]P)
        (P) -- ([shift={(-1/2,-sin{60})}]P)
        (P) -- ([shift={(-1/2,+sin{60})}]P);
  \draw[blue,thick]
        (Q) -- ([shift={(1,0)}]Q)
        (Q) -- ([shift={(-1/2,-sin{60})}]Q)
        (Q) -- ([shift={(-1/2,+sin{60})}]Q);
}
\end{tikzpicture}
\end{document}

enter image description here

Some may not like the "tendrils". They can be removed as follows:

\documentclass{standalone}    
\usepackage{tikz}
\begin{document}    
\begin{tikzpicture}
  \def\t{1/3};
  \def\s{1};
  \def\nrow{3}
  \def\ncol{8}
  \foreach \i in {0,...,\ncol}
  \foreach \j in {0,...,\nrow} {
  \coordinate (P) at (3*\i*\t,2*sin{60}*\j*\s);
  \coordinate (Q) at ([shift={(3*\t/2,sin{60}*\s)}]P);
  \ifnum\j>0 
    \draw[blue,thick] (P) -- ([shift={(-\t/2,-sin{60}*\s)}]P);
  \fi  
  \draw[blue,thick]        
        (P) -- ([shift={(\t,0)}]P)        
        (P) -- ([shift={(-\t/2,+sin{60}*\s)}]P);        
  \ifnum\j<\nrow 
    \draw[blue,thick](Q) -- ([shift={(-\t/2,+sin{60}*\s)}]Q);
  \fi    
  \ifnum\i<\ncol
    \draw[blue,thick](Q) -- ([shift={(\t,0)}]Q);
  \fi 
  \draw[blue,thick](Q) -- ([shift={(-\t/2,-sin{60}*\s)}]Q);                
}
\end{tikzpicture}    
\end{document}

enter image description here

kabenyuk
  • 604