Today I was trying to draw a rectangle rotated by -45° using TikZ, and came across some (in my opinion) weird behaviour: The rotate around
key in the \draw
command changes its behaviour based on whether the following path is specified per hand or via predefined coordinates, and also on whether the end point of the path (rectangle in this case) is specified directly or relative to the starting point. An example:
\documentclass[border=2mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
%Original rectangle (square in this case):
\coordinate (A) at (10,10);
\draw[black,ultra thick] (A) rectangle +(10,10);
%Point I want to rotate around:
\filldraw[blue] (15,15) circle (5pt);
%Option 1 (does NOT work as expected):
\draw[red,ultra thick,rotate around={45:(15,15)}] (A) rectangle +(10,10);
%This option seems not to care about the rotation point specification at all.
%I've tried a few different coordinates but it always just rotates around (A)
%Option 2 (also does NOT work, but in a different way which I don't understand at all):
\draw[orange,ultra thick,rotate around={45:(15,15)}] (A) rectangle (20,20);
%Option 3 (works as expected):
\draw[green,ultra thick,rotate around={45:(15,15)}] (10,10) rectangle +(10,10); %also works with (10,10) rectangle (20,20);
\end{tikzpicture}
\end{document}
Is there a way to get the command to work properly with predefined coordinates? And, in the same move, is there also a comparably easy way to rotate a shape around its center without having to explicitly calculate the center coordinates (easy in this case, but might be harder in others)? I'm planning to draw something which might involve a lot of rotated shapes, and I'd like to specify as few coordinates as possible. Here's an example of what I would ideally like to have in the end:
\coordinate (A) at (10,10);
\draw[other options, rotate around={45:center}] (A) rectangle +(5,5);
Thanks in advance!
transform canvas={rotate around={45:(15,15)}}
(gives same result for all examples)([rotate around={45:(15,15)}]A)
instead of(A)
transform canvas
command rotates the entire figure. That is not what I want to do; I only want to rotate individual shapes within a figure. Also, if I use([rotate around={45:(15,15)}]A)
instead of(A)
, somehow the entire figure is shifted instead of rotated...