1

I would like to generalize this diagram and place it before the \begin{environment} command, so I can just simply/easily change the numbers as I am rotating the square. I would appreciate if I can be helped out on this.

enter image description here

\documentclass[a4paper, 12pt, openany]{book}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns, matrix,3d,arrows.meta,bending,perspective, positioning, calc, math,arrows,shapes,fit}
\usepackage{tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}

    % draw the background
    \draw [line width=1.5pt, fill=gray!2] (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;

    \coordinate[label=left:$2$]  (A) at (0,0);
    \coordinate[label=right:$3$] (B) at (4,0);
    \coordinate[label=above:$1$] (C) at (0,4);
    \coordinate[label=above:$4$] (D) at (4,4);

  
\draw[fill=yellow!30] (4,4) -- (3.5,4) -- (3.5,3.5) -- (4, 3.5);

\draw[fill=yellow!30] (4,0) -- (3.5,0) -- (3.5,0.5) -- (4, 0.5);

\draw[fill=yellow!30] (0,4) -- (0.5,4) -- (0.5,3.5) -- (0, 3.5);

\draw[fill=yellow!30] (0,0) -- (0.5,0) -- (0.5,0.5) -- (0, 0.5);

\draw [line width=1.5pt] (A) -- (B) -- (D) -- (C) -- cycle;

\coordinate (A) at (5,2);
\coordinate (B) at (7,2);
\coordinate (C) at (6,1.2);
\draw[red, ultra thick, ->] (A) to [bend right=50] (B);
\node at (C) {$r_{90^\circ}=r$};

  \end{tikzpicture}
\hspace{0.5cm}
\begin{tikzpicture}
   \draw [line width=1.5pt, fill=gray!2] (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle;

    \coordinate[label=left:$1$]  (A) at (0,0);
    \coordinate[label=right:$2$] (B) at (4,0);
    \coordinate[label=above:$4$] (C) at (0,4);
    \coordinate[label=above:$3$] (D) at (4,4);

  
\draw[fill=yellow!30] (4,4) -- (3.5,4) -- (3.5,3.5) -- (4, 3.5);

\draw[fill=yellow!30] (4,0) -- (3.5,0) -- (3.5,0.5) -- (4, 0.5);

\draw[fill=yellow!30] (0,4) -- (0.5,4) -- (0.5,3.5) -- (0, 3.5);

\draw[fill=yellow!30] (0,0) -- (0.5,0) -- (0.5,0.5) -- (0, 0.5);

\draw [line width=1.5pt] (A) -- (B) -- (D) -- (C) -- cycle;
  \end{tikzpicture}
\end{center}
\end{document}
1
  • Either create a \newcommand or a \pic that draws the square and the right angles, maybe even with the number around it, as parameters.
    – SebGlav
    Feb 12, 2023 at 14:08

1 Answer 1

2

Here's one of many solutions, with a \newcommand:

generalizing a picture

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}

\newcommand{\mysquare}[4]%
    {%
    \def\myradius{4cm}
    \begin{tikzpicture}
    \foreach \l [count=\i from 0] in {#1,#2,#3,#4}
        {
        \draw[fill=yellow!20] (45+90*\i:\myradius) rectangle (45+90*\i:0.8*\myradius);
        \node at (45+\i*90:1.1*\myradius) {\l};
        }
    \draw[line width=1.5pt] (45:\myradius) rectangle (225:\myradius);
    \end{tikzpicture}
    }
    
\begin{document}
    \mysquare{4}{1}{2}{3}
    \hspace*{5mm}
    \raisebox{2cm}
        {   
        \begin{tikzpicture}
            \draw[red, ultra thick, ->] (0,0) to [bend right=50] (2,0);
            \node at (1,-.75) {$r_{90^\circ}=r$};
        \end{tikzpicture}
        }
    \hspace*{5mm}
    \mysquare{1}{2}{3}{4}
\end{document}
2
  • 1
    I misplaced the numbers on the right square but you get the point.
    – SebGlav
    Feb 12, 2023 at 14:36
  • 1
    Of course, I do. Thanks so much. You can help thumbs up my question. Feb 12, 2023 at 14:54

You must log in to answer this question.

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