Transform defined coordinates in TikZ

As the other questions linked have explained the issue, I'll not go over old ground. Looking at the code there does not seem to be an easy way to say "Apply the following style (say, shift={(2,3)}) to all of the following points.". There is no every point style (contrast the many every path or every node or ...). Moreover, adding one in would not be simple as the coordinate parser needs to see the [ to invoke the bit that does the transformation (the code here has the illuminating comment uhoh... options! at this point).

So there's not a really, really simple solution. But there is a way to make the proper way to do this a little simpler using styles.

\documentclass{article}
%\url{http://tex.stackexchange.com/q/98924/86}
\usepackage{tikz}

\tikzset{
  c/.style={every coordinate/.try}
}

\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (1,0);
\coordinate (c) at (0,1);
\draw (a) -- (b) -- (c) -- cycle;
\begin{scope}[every coordinate/.style={shift={(2,3)}}]
    \draw ([c]a) -- ([c]b) -- ([c]c) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}

shifted triangle


It isn't straightforward at all to add a general every coordinate style. But, a \iftikztransformnodecoordinates is fairly simply to hack.

\documentclass{standalone}
\usepackage{tikz}

\makeatletter
\newif\iftikztransformnodecoordinates
\tikzset{transform node coordinates/.is if=tikztransformnodecoordinates}


\def\tikz@parse@node#1(#2){%
    \pgfutil@in@.{#2}%
    \ifpgfutil@in@
        \tikz@calc@anchor#2\tikz@stop%
    \else%
        \tikz@calc@anchor#2.center\tikz@stop%
        \expandafter\ifx\csname pgf@sh@ns@#2\endcsname\tikz@coordinate@text%
        \else
            \tikz@shapebordertrue%
            \def\tikz@shapeborder@name{#2}%
        \fi%
    \fi%
    \iftikztransformnodecoordinates%
        \pgf@pos@transform{\pgf@x}{\pgf@y}%
    \fi
    \edef\tikz@marshal{\noexpand#1{\noexpand\pgfqpoint{\the\pgf@x}{\the\pgf@y}}}%
    \tikz@marshal%
}

\begin{document}

\begin{tikzpicture}

\coordinate (a) at (0,0);
\coordinate (b) at (1,0);
\coordinate (c) at (0,1);

\draw (a) -- (b) -- (c) -- cycle;

\draw [red, transform node coordinates, rotate=10] 
    (a) -- (b) -- (c) -- cycle;

\draw [green, transform node coordinates, shift={(1,1)}] 
    (a) -- (b) -- (c) -- cycle;

\draw [blue, transform node coordinates, rotate=10, shift={(1,1)}] 
    (a) -- (b) -- (c) -- cycle;

\end{tikzpicture}

\end{document}

node_coordinate_transforms

Not sure if it is 100% robust though.


In TikZ/pgf, transformations are applied only to numeric coordinates. To retrieve original numeric coordinates from nodes or coordinates, you may use a let operation:

enter image description here

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,scopes}
\begin{document}
\begin{tikzpicture}
  \coordinate (a) at (0,0);
  \coordinate (b) at (1,0);
  \coordinate (c) at (0,1);
  \draw (a) -- (b) -- (c) -- cycle;

  \draw[blue] let \p{a}=(a),\p{b}=(b),\p{c}=(c) in
  {[rotate=30] (\p{a}) -- (\p{b}) -- (\p{c}) -- cycle}
  {[shift={(2,3)}] (\p{a}) -- (\p{b}) -- (\p{c}) -- cycle};
\end{tikzpicture}
\end{document}