There are several method, as describle in the section Coordinate Transformations in the pgfmanual.
One way is to set a coordinate transformation matrix directly, via cm
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[scale = 0.5]
\draw [->](-5,0) -- (5,0); %x-axis
\draw [->](0,-5) -- (0,5); %y-axis
\draw[green] (1,1) -- (1,-1) -- (-1,-1) -- (-1,1) -- (1,1); %square around the origin
\draw[blue,cm={cos(45) ,-sin(45) ,sin(45) ,cos(45) ,(3 cm,5 cm)}] (1,1) -- (1,-1) -- (-1,-1) -- (-1,1) -- (1,1);
\end{tikzpicture}
\end{document}
Be careful, you need to use this with the right order the transformations. With cm, you don't have the choice, it's always the rotation and then the translation. And the pgfmanual says: "Usually, you do not use this option directly."
A different solution is to use shift
and rotate
:
\draw[blue,shift={(3 cm,5 cm)},rotate=45] (1,1) -- (1,-1) -- (-1,-1) -- (-1,1) -- (1,1);
\draw[orange,rotate=45,shift={(3 cm,5 cm)}] (1,1) -- (1,-1) -- (-1,-1) -- (-1,1) -- (1,1);
(Comment by Caramdir:) For this you need to remember that TikZ composes transformations in the opposite order than the naturally expected one (i.e. it acts on the coordinate plane, not on the objects).
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\begin{document}
\begin{tikzpicture} [fig/.style={regular polygon, regular polygon sides=3}]
\foreach \i in {0,1,2,3}{%
\begin{scope} [rotate around={20*\i:(\i*4,0) },every node/.style={transform shape}]
\node[fig,draw] (t) at (\i*4,0) {Text};
\node at ([shift={(60:8pt)}]t.60) {A}; % I prefer more possibilities
\node at ([yshift=-8pt]t.south) {B}; % I prefer more possibilities
\end{scope}
}
\end{tikzpicture}
\end{document}
or with your code and like in Peter's answer
remark : a local style is better (fig/.style here is a local style)
\begin{tikzpicture}[fig/.style={regular polygon, regular polygon sides=3, label=60:A,label=below:B}]
\foreach \i in {0,1,2,3}{
\begin{scope}[rotate around={20*\i:(\i*4,0) }, ultra thick, transform shape]
\node[fig,draw] at(\i*4,0) {Text};
\end{scope}
}
\end{tikzpicture}
Best Answer
There might be a confusion here relating to PSTricks habits.
First of all,
\coordinate (P) (0,0);
defines a coordinate at the origin with the name(P)
. This name is related to origin now. Then you addThis command first does this bit;
which says that go to point
(P)
, which is the origin now from the previous command, and put a node there with texthello
. Then, the option kicks in and says that you should also rotate this path, which is going to origin and putting a node, 45 degrees. But since the path is actually not moved, as we are still at the origin, no rotation is created. If you want to rotate the node then it should be supplied to the node options and not to the path options, henceis the command that you have to enter. But since you are trying to put a node and not to draw anything you can directly use