Rotate a scope with named coordinates defined outside the scope

rotatingtikz-pgf

Here is the code


  \begin{figure}[h]
    \begin{tikzpicture}
      \coordinate (E) at (1.5,0);
      \coordinate (F) at ($(E)+(20:15)$);
      \coordinate (G) at ($(F)+(110:.2)$);
      \coordinate (H) at ($(E)+(110:.2)$);
      \coordinate (I) at ($(E)+(20:5)$);
      \draw[fill,color=gray!50] (E) -- (F) -- (G) -- (H) -- cycle;
      \begin{scope}[rotate around={-40:(I)}]
        \draw[dashed] (E) -- (F) -- (G) -- (H) -- cycle;
      \end{scope}
    \end{tikzpicture}
  \end{figure}

But I got the same tikzfigure drawn twice. I want the second draw to be the first one rotated -40 degrees about the coordinate I.
I have noticed that the named coordinates persists in the rotation, but how can I achieve what I desired? It is dull to redefine the coordinates inside the scope and I want to avoid such a drudgery.

Best Answer

You can define the coordinates in a macro if you want to minimize your code.

\documentclass{standalone}
\usepackage{tkz-euclide}
\begin{document}
  \newcommand{\mycoordinates}{%
  \coordinate (E) at (1.5,0);
  \coordinate (F) at ($(E)+(20:15)$);
  \coordinate (G) at ($(F)+(110:.2)$);
  \coordinate (H) at ($(E)+(110:.2)$);
  }
\begin{tikzpicture}
       \mycoordinates
      \coordinate (I) at ($(E)+(20:5)$);
      \draw[fill,color=gray!50] (E) -- (F) -- (G) -- (H) -- cycle;
      \begin{scope}[rotate around={-40:(I)}]
     \mycoordinates
        \draw[dashed] (E) -- (F) -- (G) -- (H) -- cycle;
      \end{scope}
 \end{tikzpicture}
\end{document} 

enter image description here

Related Question