Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

\documentclass[a4paper,12pt,notitlepage]{article}
\usepackage{tikz}
\usepackage{pgffor}
\usetikzlibrary{scopes}
\newcommand{\drawCircularLines}[2]
{
    \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;
    }
}

\newcommand{\moireeTest}[3][0]
{
    \begin{figure}
    \centering
    \begin{tikzpicture}
        { [color=red]
            \drawCircularLines{#2}{0}
        }
        { [color=blue]
            \drawCircularLines{#3}{#1}
        }
    \end{tikzpicture}
    \caption{Moiree Test mit #2 und #3 Strichen (Delta #1).}
    \end{figure}
}

\begin{document}

\pgfmathparse{360/80/1*0}
\moireeTest[\pgfmathresult]{5}{3}

\end{document}

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

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

\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

\expandafter\moireeTest\expandafter[\pgfmathresult]{5}{3}

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.

\pgfmathsetmacro\mycustomresult{360/80/1*0}
\moireeTest[\mycustomresult]{5}{3}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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