Rectangle behaving strangely within rotated scope

By default, nodes are insensitive to transformations. For them to apply, it is necessary to add the tranform shape option.

I quote the TikZ 3.1.4b manual:

17.7 Transformations

It is possible to transform nodes, but, by default, transformations do not apply to nodes. The reason is that you usually do not want your text to be scaled or rotated even if the main graphic is transformed. Scaling text is evil, rotating slightly less so. However, sometimes you do wish to transform a node, for example, it certainly sometimes makes sense to rotate a node by 90 degrees

screenshot

\documentclass[]{article}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

    \begin{figure}
      \centering
      \begin{tikzpicture}[text=black,text centered,text width=1.5cm]

        \def \n {5}
        \def \radius {3cm}
        \node[circle, draw] (c) at (0, 0) {C};

        \foreach \s in {1,...,\n} {

            \begin{scope}[shift={({-(360/\n * (\s-1)) + 90}:\radius)},rotate={-360/\n*(\s-1)},transform shape]
                \node[] (id) at (0, 4) {Id : \s};
                \node[circle, draw] (a) at (0, 3) {A};
                \node[circle, draw] (b) at (0, 0) {B};
                \draw[->] (a) -- (b);
                \draw[->] (b) -- (c);
                \draw[thick] ($(id.north west)+(-0.6,0.6)$)  rectangle ($(b.south east)+(0.6,-0.6)$);
            \end{scope}

        }

      \end{tikzpicture}
    \end{figure}

\end{document}

An another approach:

\documentclass[tikz, margin=3mm]{standalone}

\begin{document}
\begin{tikzpicture}[
C/.style = {circle, draw, fill=white, minimum size=\radius, sloped},
R/.style = {draw, minimum height=\radius+2mm, minimum width=3*\radius+3mm,
             rotate=\ang, right}
                    ]

\def\n{5}
\def\radius {7mm}
\node (c) [C] {C};
%
\foreach \i [count=\s from 0] in {1,...,\n}
{
\pgfmathsetmacro{\ang}{90+\s*360/\n}
\draw[<-] (c) -- node[C] {B} ++ (\ang:22mm)
              -- node [C, near end] {A} ++ (\ang:\radius);
\node (r\i) [R] at (\ang:\radius+1mm) {};
\node[rotate=\ang,right] at (r\i.east) {Id=\i};
}
\end{tikzpicture}
\end{document}

enter image description here

If you like to have labels of branches aligned with outer lines of rectangles, then you only need to replace last code line with

\node[rotate=270+\ang,right, anchor=north] at (r\i.east) {Id=\i};

result is shown at example in addendum.

Adendum: Inspired with comments of @Schrödinger's cat (thank you very much, I learned something new about TikZ) the solution where is used key rotate fit . Using it the definition of rectangles become simpler and also autocratically adopt to position of circle shaped nodes:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                fit}

\begin{document}
\begin{tikzpicture}[
C/.style = {circle, draw, minimum size=\radius, 
            inner sep=0pt, sloped},
R/.style = {draw, inner sep=1mm, rotate fit=\ang, fit=#1},  % <--- for rotate fit nodes
every edge/.style = {draw, semithick, -{Straight Barb[angle=60:2pt 3]}}
                    ]

\def\n{5}
\def\radius {7mm}
\node (c) [C] {C};
%
\foreach \i [count=\s from 0] in {1,...,\n}
{
\pgfmathsetmacro{\ang}{90+\s*360/\n}
\path   (c) -- node (c1\i) [C] {B} ++ (\ang:3*\radius)
            -- node (c2\i) [C, at end] {A} ++ (\ang:0.5*\radius);
\draw   (c2\i) edge (c1\i)  (c1\i) edge (c);
\node (r\i) [R=(c1\i)(c2\i)] {}; % <--- "used rotate fit"
\node[rotate=270+\ang,
      right, anchor=south, font=\footnotesize] at (r\i.east) {$\mathrm{Id}=\i$};
}
\end{tikzpicture}
\end{document}

It gives:

enter image description here

Tags:

Tikz Pgf