# Calculate label angle from a value list

As a beginner of tex and tikz i stuck on array handling together with foreach. I would like to draw two circle with text along its circumference.

\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenx}
\usetikzlibrary{decorations.text}
\begin{document}
\sffamily
\begin{tikzpicture}[
black,
ultra thick,
planet/.style = {draw,fill,circle,inner sep=#1},
circle label/.style = {
postaction={
decoration={
text along path,
text = {#1},
text align=center,
text color=black,
reverse path,
},
decorate,
}
}
]
\filldraw[white] (-8,-8) rectangle (9,10);
\path[circle label={|\large|Circle one}] (0,-8-.2) arc (-90:360-90:8+.2);
\draw[color=black,fill=gray!15] (0,0) circle (8);
\path[circle label={|\large|Inner Circle}] (0,-4-.2) arc (-90:360-90:4+.2);
\draw[color=black,fill=black!20] (0,0) circle (4);

% Values
\pgfkeys{/90/.code=Point A,
/0/.code=Point B,
/180/.code=Point C,
/270/.code=Point D}

\foreach \angle in {0,90,180,270}
\draw (\angle:2.75) -- (\angle:2.75cm) node {\pgfkeys{\angle}};

\end{tikzpicture}
\end{document}


I figured out how to draw the labels in the right angles. But i would like to create a list with its Point's and proceed the rest automatically.

As an example: I add an additional point to the pgfkeys (without angle) and 360 is divided by the count of items. For every loop the next item is removed from list and placed along the path.

• You want to do it with pgfkeys or \foreach?
– user11232
Commented Aug 1, 2014 at 11:07
• In my case it doesn't matter. The important part is to not have to calculate the angle by hand. Commented Aug 2, 2014 at 17:56

## 1 Answer

Next code shows a solution with foreach. The command placetext has two parameters, ths first one is the list of labels to distribute and the second the cicle radius. The first foreach counts total items number and the second draws them along the circle.

\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenx}
\usetikzlibrary{decorations.text}

\newcommand{\placetext}[2]{
\foreach \item [count=\totalitems] in {#1};
\foreach \item [count=\numitem, evaluate=\numitem as \angle using {(\numitem-1)*360/\totalitems}] in {#1}
\draw (\angle:#2) node {\item};
}

\begin{document}
\sffamily
\begin{tikzpicture}[
black,
ultra thick,
planet/.style = {draw,fill,circle,inner sep=#1},
circle label/.style = {
postaction={
decoration={
text along path,
text = {#1},
text align=center,
text color=black,
reverse path,
},
decorate,
}
}
]
\filldraw[white] (-8,-8) rectangle (9,10);
\path[circle label={|\large|Circle one}] (0,-8-.2) arc (-90:360-90:8+.2);
\draw[color=black,fill=gray!15] (0,0) circle (8);
\path[circle label={|\large|Inner Circle}] (0,-4-.2) arc (-90:360-90:4+.2);
\draw[color=black,fill=black!20] (0,0) circle (4);

% Values
%\pgfkeys{/90/.code=Point A,
%    /0/.code=Point B,
%    /180/.code=Point C,
%    /270/.code=Point D}
%
%\foreach \angle in {0,90,180,270}
%\draw (\angle:2.75) -- (\angle:2.75cm) node {\pgfkeys{\angle}};

\placetext{Point A, Point B, Point C, Point D, Point E}{2.75}
\placetext{Point A, Point B, Point C}{6.75}

\end{tikzpicture}
\end{document}