3

This question partly extends on this post.


I am using the following command line to rotate a line that I use to dimension the radius of a circle, as mentioned in an answer to the above mentioned post:

\draw[-latex, rotate around={45:(0,0)}] (0,0) -- (6,0)  node [midway,fill=white] {$\text{Text}$};

The problem is, I am not using (6,0) but a point (p) that is calculated with polar coordinates. As soon as I replace (6,0) by (p), the rotation doesn't work.


How do I workaround the fact that rotate around apparently doesn't work for points in polar coordinates?


Edit: I added the exact code I used to calculate the point with polar coordinates (it's called last1):

\documentclass{standalone}
\newcommand{\ts}[1]{\textnormal{#1}}
\usepackage{tikz} 
\usetikzlibrary{positioning,arrows,calc,math,angles,quotes,trees,mindmap,through}
%include other needed packages here   
\begin{document}

\begin{tikzpicture} \draw[-latex] (-4,0) -- (4,0) node[right]{$\ts{Re}(r)$}; \draw-latex -- (0,4) node[above] {$\ts{Im}(r)$}; \def\z{0} \def\zz{-1.5} \def\zzz{-5} \coordinate (last1) at (0:0); \coordinate (last2) at (0:0); \coordinate (last3) at (0:0); \foreach \y in {1,2,3,4,5,6,7,8,9,10,11,12,13,14} { \pgfmathsetmacro{\o}{0.05random(0,1000)}; \pgfmathsetmacro{\t}{0.005random(0,100)}; \draw[->] (last1) -- ++ (\o\z:\t) coordinate (last1); \draw[->] (last2) -- ++ (\o\zz:\t) coordinate (last2); \draw[->] (last3) -- ++ (\o*\zzz:\t) coordinate (last3);
}; \node at (0,0) [draw,dotted, circle through={(last1)}] {}; \draw[-latex,line width=0.7mm] (0:0) -- (last3); \draw[-latex, rotate around={45:(0,0)}] (0,0) -- (last1) node [midway,fill=white] {$\sum |b_{z_1z_2\cdots z_N}|^2 =1$}; \end{tikzpicture}

\end{document}

manuel459
  • 319
  • 1
    What's the exact \draw command you are using that doesn't work? – Dai Bowen Mar 30 '23 at 18:02
  • I added the command to the question. – manuel459 Mar 30 '23 at 18:03
  • 1
    I see, it's not just rotate around, rotate=45 is ignored for (0,0) -- (last1) but respected for (0,0) -- (4,0) – Dai Bowen Mar 30 '23 at 18:43
  • Yes, I also tried scope but the rotation doesn't work. Somehow the polar coordinates are the problem... – manuel459 Mar 30 '23 at 18:44
  • So what I aim for is a arrow that points from the origin (0,0) in a 45° angle towards the dotted circle - therefore dimensioning the radius. I tried to achieve this by drawing the arrow (measure, dimensioning) from (0,0) to (last1) and then rotating it 45° around the origin (0,0). This, I totally took from the linked post (answer from Qrrbrbirlbel). – manuel459 Mar 30 '23 at 19:22
  • 1
    I see, so what you mean is that \draw[-latex, rotate around={45:(0,0)}] (0,0) -- (4,0); works (and also \draw[-latex, rotate around={45:(0,0)}] (0,0) -- (0:4); by the way), but what does not work is \draw[-latex, rotate around={45:(0,0)}] (0,0) -- (last1);, although (last1) is also defined as (0:x), right? Well, I don't know why that is and it is surely strange at a first glance, but what would work is \draw[-latex] (0,0) -- ([rotate=45]last1); – Jasper Habicht Mar 30 '23 at 19:32
  • Exactly! That's the problem. Not only would but does! This is a great workaround! Thank you very much :) Please feel free to post an answer! – manuel459 Mar 30 '23 at 19:36
  • 1
    See [https://tex.stackexchange.com/q/98924/47927]. The reason is obviously that the coordinate is defined outside the scope and hence it is not transformed. Therefore, you need to transform it separately. – Jasper Habicht Mar 30 '23 at 19:38

1 Answers1

2

I have to admit that it took me a while to get what you mean, so I try to restate it with my own words:

The problem is that \draw[-latex, rotate around={45:(0,0)}] (0,0) -- (4,0); would work (the resulting line is rotated by 45 degrees). Similary, \draw[-latex, rotate around={45:(0,0)}] (0,0) -- (0:4); would work. But as soon as you replace one of the coordinates of your path with a previously defined coordinate, the transformation does not work anymore. So \draw[-latex, rotate around={45:(0,0)}] (0,0) -- (last1); would actually not result in a rotated line, although the coordinate (last1) is defined as (0:<x>).

This problem seems to be the same as in this other question. The reason for this is that the coordinate was defined outside the scope of the transformation (in fact it is not exactly a scoping issue but a feature that applies an inverse transformation on anchor points and which is quite sensible in most cases*; thanks to Qrrbrbirlbel!). I can actually understand that this behaviour is quite peculiar, at least not directly obvious.

So, what you need to do is to explicitly transform the previously defined coordinate. Since the other coordinate of your path is (0,0), you don't need to transform the rest of the path: You can write \draw[-latex] (0,0) -- ([rotate=45]last1); and will get a line rotated by 45 degrees.

\documentclass[border=10pt]{standalone}
\usepackage{tikz}

\begin{document} \begin{tikzpicture}

\draw[-latex, red, rotate around={10:(0,0)}] (0,0) -- (4,0);

\draw[-latex, magenta, rotate around={20:(0,0)}] (0,0) -- (0:4);

% behaviour not as expected \coordinate (last1) at (4,0); \draw[-latex, blue, thick, rotate around={30:(0,0)}] (0,0) -- (last1);

% behaviour not as expected \coordinate (last2) at (0:4); \draw[-latex, cyan, rotate around={40:(0,0)}] (0,0) -- (last2);

\coordinate (last3) at (4,0); \draw[-latex, green] (0,0) -- ([rotate=50]last3);

\coordinate (last4) at (0:4); \draw[-latex, yellow] (0,0) -- ([rotate=60]last4);

\end{tikzpicture} \end{document}

enter image description here


* See section 106.3.1 "Referencing Anchors of Nodes in the Same Picture" in the PGF manual.
  • 1
    This is badly documented in the PGF part of the manual and uses @-ridden code as an example to resolve that. – Qrrbrbirlbel Mar 30 '23 at 20:20
  • @Qrrbrbirlbel So, it is not exactly a scoping issue but a feature that applies an inverse transformation on anchors, right? Hm ... interesting – Jasper Habicht Mar 30 '23 at 20:31
  • Great analyzation, very helpful! Thank you. – manuel459 Mar 30 '23 at 21:44
  • 1
    Nodes (and therefore coordinates) are fixed points on the paper. That's their whole point. (Drawing an arrow to a node should always draw an arrow to the node and not to its transformed position.) Their are not a 2D variable that can be used later. (But it would be great if there were something like that but I think that is already covered by the linked Q&A.) – Qrrbrbirlbel Mar 30 '23 at 21:47