I have the following problem: I want to draw some moiree effects in tikz. This seems to be no problem. I did it without any error (two circles of trapezia). Now the two rings should be moved a bit. I added things and nothing worked anymore. I give you a reduced code below. Unfortunately the problem arises only if I calculate the movement by pgfmath. If I give them directly, all right, no error.

The (reduced) code:

    \foreach \i 
        evaluate=\i as \startAngle using 360/#1*(\i-1)+#2,
        evaluate=\i as \endAngle using 360/(2*#1)*(2*\i-1)+#2
    in {1,...,#1}
        \draw (\startAngle:2cm) -- (\startAngle:3cm) -- (\endAngle:3cm) -- (\endAngle:2cm) -- cycle;

        { [color=red]
        { [color=blue]
    \caption{Moiree Test mit #2 und #3 Strichen (Delta #1).}




If you replace the \pgfmathresult by 0 or delete the optional argument you see the correct 3 trapezia in blue.

Can you tell me, where is my fault? Thanks


\pgfmathresult is a temporary register and it's being used very frequently by TikZ itself. So before you use it in your custom macro, it has been overwritten many times by TikZ. You can either expand the value of the \pgfmathresult by


when you are calling it such that it's current value is passed or you can set the result to some other macro that is not disturbed by other things e.g.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.