# How to draw lines between nodes that point at the node center, but stop at the nodes edge

I'm drawing nodes on a circle and switched from drawing lines based on coordinates to drawing them based on named nodes.

The problem now is, that with the following code the lines stop at the edges of the nodes, but don't point at the center.

How do I fix this?

\begin{tikzpicture}
\xdef\nodes{16}
\pgfmathsetmacro{\nodesminusone}{\nodes-1}
\pgfmathsetmacro{\N}{log2(\nodes)}
\draw (0,0) circle (6);

\foreach \i in {0,...,\nodesminusone}

\foreach \i in {0,...,\nodesminusone}{
\foreach \j in {0,...,\N}{
\pgfmathsetmacro{\result}{mod(\i+2^\j,\nodes)}
\draw[->,thick,color=black!10] (node\i) -- (node\result);

}
}

\foreach \i in {2} {
% predecessor
\pgfmathsetmacro{\result}{mod(\i-1,\nodes)}
\draw (node\i) -- (node\result);

% successor
\pgfmathsetmacro{\result}{mod(\i+1,\nodes)}
\draw (node\i) -- (node\result);

% fingers
\foreach \j in {0,...,\N}{
\pgfmathsetmacro{\result}{mod(\i+2^\j,\nodes)}
\draw[->,color=blue,thick] (node\i) -- (node\result);
}
}
\end{tikzpicture}

-

Replace \pgfmathsetmacro with \pgfmathtruncatemacro.

The reason why this happens is that \pgfmathsetmacro returns a floating (or fixed?) point number, not an integer. For example:

    \foreach \j in {0,...,\N}{
\pgfmathsetmacro{\result}{mod(\i+2^\j,\nodes)}
\draw[->,color=blue,thick] (node\i) -- (node\result);
}


Here \result will be 0.0, 1.0, etc. (whatever the result of mod is). However (node1.0) means "Node 'node1' at angle 0degr", which draws the arrows to this point. With \pgfmathtruncatemacro the .0 will be truncated and only (node1) etc. is used which gives the wanted result.

-
perfect, thanks! This is hard to debug... any tipps on how I could have found this myself? –  Zoran Zaric Feb 4 '11 at 23:55
The most difficult thing is to know where to start. But it is always good to look at your intermediate results. You could have looked at the definition of \result, i.e. using \show\result or better \edef\A{(node\i) -- (node\result)}\show\A to see what it passed to the \draw. –  Martin Scharrer Feb 5 '11 at 0:07
Also, minimizing the document to two nodes plus one line might have shown the error more easily. Your code is already to big and complicated to post it like it is anyway. –  Martin Scharrer Feb 5 '11 at 0:09
thanks a lot for the clarification –  Zoran Zaric Feb 5 '11 at 0:12
@Zoran: You are welcome. Happy TeXing! –  Martin Scharrer Feb 5 '11 at 0:22