[Tex/LaTex] TikZ: how to apply an affine transformation

tikz-pgf

I would like to draw something like this:

enter image description here

The best I can do so far:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\resizebox{0.95\textwidth}{!}{
\begin{tikzpicture}
\newcommand\Square{+(-1,-1) rectangle +(1,1)}
\draw (0,0) rectangle (8,6);\node at (4,0.5) {$I_1$};
\node[label=$p$]  (p) at (3,4) {};
\draw [orange] plot [only marks, mark size=2.5, mark=*] coordinates {(3,4)};
\draw[fill =blue,fill opacity=0.1] (p)  \Square;

\draw (10,0) rectangle (18,6);\node at (14,0.5) {$I_2$};
\node[label=below:$p'$]  (p') at (12.5,2.7) {};
\draw [orange] plot [only marks, mark size=2.5, mark=*] coordinates {(12.5,2.7)};

\draw[thick,->] (p) edge[bend right] (p');
\draw[fill =blue,fill opacity=0.1,rotate=50] (p') \Square;
\end{tikzpicture}}
\end{document}

enter image description here

The result is not very satisfactory. Hope somebody can help. Thank you in advance.

Best Answer

This can be done quite trivially by using scopes and coordinate transformations.

First thing, intstead of using the "advanced" coordinates routines, simply do:

\fill[orange] (3,4) circle (2.5pt);

which gives the same.

Then onwards to transformations.

The second rectangle can easily be drawn with the same commands and a scope

% Draw next rectangle, move everything 10cm to the right
\begin{scope}[xshift=10cm]

   \draw (0,0) rectangle (8,6);
   \node at (4,0.5) {$I_2$};
   \node[label=$p'$] (p') at (3,4) {};
   \fill[orange] (p') circle (2.5pt);

\end{scope}

Now for the remaining part.

You can do with another scope and transform the coordinates in that scope.
This can be done using the cm={x,xy,yx,y,(coord)} construct. It lets you create a matrix transformation for (x,y) coordinates.

The full thing becomes:

\begin{tikzpicture}[scale=.7]
  \newcommand\Square{+(-1,-1) rectangle +(1,1)}

  % Draw first rectangle and name
  \draw (0,0) rectangle (8,6);
  \node at (4,0.5) {$I_1$};
  \node[label=$p$]  (p) at (3,4) {};
  % Fill square
  \draw[fill=blue,fill opacity=0.1] (p) \Square;
  \draw[->,>=latex] (p) ++(-1,-1) -- ++(2.5,0);
  \draw[->,>=latex] (p) ++(-1,-1) -- ++(0,2.5);
  \fill[orange] (p) circle (2.5pt);

  % Draw next rectangle
  \begin{scope}[xshift=10cm]

    \draw (0,0) rectangle (8,6);
    \node at (4,0.5) {$I_2$};
    \node[label=$p'$] (p') at (3,4) {};
    \fill[orange] (p') circle (2.5pt);

    \begin{scope}[cm={.74,.74,-.74,.74,(0,0)}]
      \draw[->,>=latex] (p') ++(-1,-1) -- ++(2.5,0);
      \draw[->,>=latex] (p') ++(-1,-1) -- ++(0,2.5);
      \draw[fill=blue,fill opacity=0.1] (p') \Square;

    \end{scope}

  \end{scope}

  \draw[thick,->] (p) edge[bend right] (p');
\end{tikzpicture}

And it produces this:

enter image description here

You can easily adapt the different elements in the transformation.