4

I used Geogbra to draw this pattern of multiple squares. Then, I exported the figure as TikZ code. The generated code is the following:

\documentclass[12pt]{standalone}
\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(-0.638792669780812,-0.5566805569105137) rectangle (6.3612073302191865,6.443319443089485);
\draw (0.,6.)-- (6.,6.);
\draw (6.,6.)-- (6.,0.);
\draw (6.,0.)-- (0.,0.);
\draw (0.,6.)-- (0.,0.);
\draw (2.,6.)-- (2.,0.);
\draw (4.,6.)-- (4.,0.);
\draw (0.,2.)-- (6.,2.);
\draw (0.,4.)-- (6.,4.);
\draw (4.,6.)-- (6.,4.);
\draw (6.,4.)-- (2.,0.);
\draw (2.,6.)-- (0.,4.);
\draw (2.,6.)-- (4.,4.);
\draw (4.,4.)-- (6.,2.);
\draw (4.,4.)-- (0.,0.);
\draw (0.,4.)-- (4.,0.);
\draw (4.,0.)-- (6.,2.);
\draw (0.,2.)-- (2.,0.);
\draw (4.,4.)-- (6.,6.);
\draw (0.,6.)-- (6.,0.);
\draw (4.,6.)-- (0.,2.);
\begin{scriptsize}
\draw [fill=black] (0.,0.) circle (1.5pt);
\draw [fill=black] (6.,0.) circle (1.5pt);
\draw [fill=black] (6.,6.) circle (1.5pt);
\draw [fill=black] (0.,6.) circle (1.5pt);
\draw [fill=black] (0.,2.) circle (1.5pt);
\draw [fill=black] (0.,4.) circle (1.5pt);
\draw [fill=black] (4.,0.) circle (1.5pt);
\draw [fill=black] (2.,0.) circle (1.5pt);
\draw [fill=black] (6.,4.) circle (1.5pt);
\draw [fill=black] (6.,2.) circle (1.5pt);
\draw [fill=black] (2.,6.) circle (1.5pt);
\draw [fill=black] (4.,6.) circle (1.5pt);
\draw [fill=black] (4.,4.) circle (1.5pt);
\end{scriptsize}
\end{tikzpicture}
\end{document}

After compilation, I got this:

enter image description here

How can I draw this pattern of squares in another way?

A similar question with two pictures enter image description here

enter image description here

5

enter image description here

With two nested \foreach loops for drawing the crossed squares and another two nested \foreach loops for placing the black circles.

\documentclass[tikz,border=2pt]{standalone}
\begin{document}

\begin{tikzpicture}[line width=.2pt]
\foreach \x in {1,2,3}{%
 \foreach \y in {1,2,3}{%
  \node(p-\x\y) at (\x,\y)[draw,minimum size=1cm]{};
   \draw (p-\x\y.45)--(p-\x\y.-135) (p-\x\y.135)--(p-\x\y.-45);
 }
}
\foreach \x in {.5,3.5}{%
 \foreach \y in {.5,1.5,2.5,3.5}{%
  \node at(\x,\y)[circle,fill,inner sep=.7pt]{};
  \node at(\y,\x)[circle,fill,inner sep=.7pt]{};
 }
}
\node at(2.5,2.5)[circle,fill,inner sep=.7pt]{};
\end{tikzpicture}

\end{document}

For the second example you can use the following:

\begin{tikzpicture}[line width=.2pt]
\path (1,1) coordinate (A) (5,1) coordinate (B) (3,2) coordinate (C);
\draw (A)--(B)--(C)--cycle;
\foreach \x in {1,2,3}{%
\draw ($(A)!\x/4!(B)$)--($(A)!\x/4!(C)$)
      ($(A)!\x/4!(B)$)--($(C)!\x/4!(B)$)
      ($(C)!\x/4!(A)$)--($(C)!\x/4!(B)$);
}
\end{tikzpicture}

enter image description here

And for the third, the same for the second plus a flipped version of the second as this:

\begin{tikzpicture}[line width=.2pt]
\path (1,1) coordinate (A) (5,1) coordinate (B) (3,2) coordinate (C) (3,0) coordinate (C2);
\draw (A)--(B)--(C)--cycle (A)--(B)--(C2)--cycle;
\foreach \x in {1,2,3}{%
\draw ($(A)!\x/4!(B)$)--($(A)!\x/4!(C)$)
      ($(A)!\x/4!(B)$)--($(C)!\x/4!(B)$)
      ($(C)!\x/4!(A)$)--($(C)!\x/4!(B)$)
      ($(A)!\x/4!(B)$)--($(A)!\x/4!(C2)$)
      ($(A)!\x/4!(B)$)--($(C2)!\x/4!(B)$)
      ($(C2)!\x/4!(A)$)--($(C2)!\x/4!(B)$);
}
\end{tikzpicture}

enter image description here

1

You can obtain this cross grid by using slanted grids + clipping :

\documentclass[border=7mm]{standalone}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \clip (-\pgflinewidth/2,-\pgflinewidth/2) rectangle (3cm+\pgflinewidth,3cm+\pgflinewidth);
    \draw (0,0) grid +(3,3) [xslant=1] (-2,0) grid +(4,3) [xslant=-2] (1,0) grid +(4,3);
  \end{tikzpicture}
\end{document}

enter image description here

Or by using two grids, on of them rotated, scaled and translated :

\documentclass[border=7mm]{standalone}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \clip (-\pgflinewidth/2,-\pgflinewidth/2) rectangle (3cm+\pgflinewidth,3cm+\pgflinewidth);
    \draw (0,0) grid +(3,3) [rotate=45,scale={1/sqrt(2)},shift={(-1,-3)}] (0,0) grid +(7,6);
  \end{tikzpicture}
\end{document}

To obtain the two other figures, you can change the clipping region and change the grids transforms. For example :

\documentclass[border=7mm]{standalone}
\usepackage{tikz}
\begin{document}
  \begin{tikzpicture}
    \clip (-\pgflinewidth,-\pgflinewidth/2) -- (4cm+\pgflinewidth,-\pgflinewidth/2) -- (2cm,{2cm+\pgflinewidth/sqrt(2)});
    \draw [xslant=1](-1,0) grid +(4,3) [xslant=-2,yscale=.5] (1,0) grid +(4,4);
  \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.