# Tikz: Rotate around center when using coordinates relative to image

I'm currently trying to define my coordinates in terms of the image's east/west/south/east coordinates so that I can use the same coordinate system regardless of what image I use. However, when i try to use the \draw [rotate around={20:\O{}}, name path=a] \O{} -- \E{}; in the example below, it does not rotate the path. When instead I use coordinates in the traditional way (5,0) it rotates it just fine.

I really want to use these relative coordinates since it would mean I wouldn't have to look up the edges each time I do annotations for a new image. How can I make the rotate around functionality work with relative coordinates?

\documentclass[12pt]{article}

\usepackage{graphicx}                                   % Further formatting of figures
\usepackage{amsmath}                                    % Mathematics
\usepackage{tikz}                                       % Annotated Figures
\usetikzlibrary{intersections}                          % Detect intersections
\usetikzlibrary{calc}                                   % Calculate distances
\usetikzlibrary{positioning}                            % Better positioning tools

\begin{document}

\begin{figure}[!htb]
\centering
\begin{tikzpicture}
\node[inner sep=0pt] (img) at (0,0)
{\includegraphics[width=\textwidth]{Figures/Airfoil.png}};
%
\def\alph{50};
\def\anglechord{230};
\def\O{(img.center)};
\def\E{(img.east)};
\def\W{(img.west)};
\def\N{(img.north)};
\def\S{(img.south)};
\def\SW{(img.south west)};
\def\SE{(img.south east)};
\def\NW{(img.north west)};
\def\NE{(img.north east)};
\def\arrow{{Latex[length=2.8mm]}};
\def\arrowshort{{Latex[length=2mm]}};
% \draw[step=1,black, thick] \SW{} grid \NE{};
\draw[fill] (img.center) circle (0.1);
%
\draw [dashed, very thin, name path=horizontal] \W{} -- \W{};
\draw [dashed, very thin, name path=vertical] \S{} -- \N{};
\path [name path = right] \SE{} -- \NE{};

\draw [rotate around={20:\O{}}, name path=a] \O{} -- \E{};
\end{tikzpicture}
% \caption{caption}
% \label{fig:topconfig}
\end{figure}

\end{document}

• Possible duplicate of Drawing on an image with TikZ – AndréC Nov 2 '18 at 13:08
• Negative. I tried that solution already and it didn't work at all. The positioning according to those coordinates was extremely arbitrary and not at all as well defined as the answer makes it look. So I'm still looking for a more reliable approach. Also, this question does not ask for a way to scale coordinates, I know how to do that. I'm asking for a way to use the rotate around command. – Luc Evertzen Nov 2 '18 at 13:30

Yes, that's the behavior of TikZ. However, you are already loading the calc library, which allows you to convert symbolic coordinates to explicit ones.

\documentclass[12pt]{article}

\usepackage{amsmath}                                    % Mathematics
\usepackage{tikz}                                       % Annotated Figures
\usetikzlibrary{intersections}                          % Detect intersections
\usetikzlibrary{calc}                                   % Calculate distances
\usetikzlibrary{positioning}                            % Better positioning tools

\begin{document}

\begin{figure}[!htb]
\centering
\begin{tikzpicture}
\node[inner sep=0pt] (img) at (0,0)
{\includegraphics[width=\textwidth]{example-image-duck}};
%
\def\alph{50};
\def\anglechord{230};
\def\O{(img.center)};
\def\E{(img.east)};
\def\W{(img.west)};
\def\N{(img.north)};
\def\S{(img.south)};
\def\SW{(img.south west)};
\def\SE{(img.south east)};
\def\NW{(img.north west)};
\def\NE{(img.north east)};
\def\arrow{{Latex[length=2.8mm]}};
\def\arrowshort{{Latex[length=2mm]}};
% \draw[step=1,black, thick] \SW{} grid \NE{};
\draw[fill] (img.center) circle (0.1);
%
\draw [dashed, very thin, name path=horizontal] \W{} -- \W{};
\draw [dashed, very thin, name path=vertical] \S{} -- \N{};
\path [name path = right] \SE{} -- \NE{};
\draw let \p1=($(img.center)$),\p2=($(img.east)$)
in [rotate around={20:\O}, name path=a,thick,red]
(\x1,\y1)-- (\x2,\y2);
\end{tikzpicture}
% \caption{caption}
% \label{fig:topconfig}
\end{figure}

\end{document}


Another possibility is to use transform canvas:

\draw [transform canvas={rotate around={20:\O{}}}, name path=a] \O{} -- \E{};


However, I'd like to warn you that this option has to be used with great care.

• First of all, thank you for the stellar example image. And of course also thanks for the conversion. I could have known that this was a possibility, but I'm still getting used to the calc package. Thank you for the help. – Luc Evertzen Nov 2 '18 at 14:31
• @LucEvertzen You have to thank samcarter and Skillmon for the picture... ;-) – marmot Nov 2 '18 at 14:33