# Drawing a chord net with TikZ

I have a problem drawing a chord network with TikZ.

This is my code so far:

\begin{tikzpicture}
\xdef\N{16}
\draw[thick] (0,0) circle (6);

\foreach \i in {0,...,15} {
% predecessor
\pgfmathparse{mod(\i-1,\N)}

% successor
\pgfmathparse{mod(\i+1,\N)}

% fingers
\foreach \j in {0,...,4}{
\pgfmathparse{mod(\i+2^\j,\N)}
}
}

\foreach \i in {0,...,15}
\node[circle,fill=white,draw=black,thick] at (-\i*\deltadegree+90:6) {\i};
\end{tikzpicture}


The problem with this code is, TikZ only draws lines from node 6 to every other node, but i thought it iterates over all nodes, calulates the destination for each finger, and draws that line.

What am I doing wrong?

-

The \pgfmathresult macro gets overwritten very quickly by TikZ. You should always assign the results to a different macro immediately, which you can do using the \pgfmathsetmacro{<macro name>}{<math expression>} command (see also this question).

Here's your code with the adaptation. Note that the lines from the "successor" loops just draw over the "predecessor" loops.

\documentclass{article}

\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\xdef\N{16}
\draw[thick] (0,0) circle (6);

\foreach \i in {0,...,15} {
% predecessor
\pgfmathsetmacro{\result}{mod(\i-1,\N)}

% successor
\pgfmathsetmacro{\result}{mod(\i+1,\N)}

% fingers
\foreach \j in {0,...,4}{
\pgfmathsetmacro{\result}{mod(\i+2^\j,\N)}