# Moving the common angle to \pstVerb produces incorrect result

Consider the following complete code first.

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}
\begin{pspicture}(-5,-5)(5,5)
\def\points{(0,0)(1,0)}%
\pstVerb{/Angles 0 def /CPX 1 def /CPY 0 def}
\multido{\i=1+1}{15}
{
\xdef\points{\points(!1 Angles 1 \i\space 1 sub sqrt atan add dup /Angles ED PtoC %
dup CPY add /CPY ED exch dup CPX add /CPX ED exch)(!CPX neg CPY neg)(!CPX CPY)}
}
\expandafter\psrline\points
\end{pspicture}

\begin{pspicture}(-5,-5)(5,5)
\def\points{(0,0)(1,0)}%
\pstVerb{/Angles 0 def /CPX 1 def /CPY 0 def}
\multido{\i=1+1}{15}
{
\pstVerb{Angles 1 \i\space 1 sub sqrt atan add /Angles exch def}%
\xdef\points{\points(!1 Angles PtoC %
dup CPY add /CPY ED exch dup CPX add /CPX ED exch)(!CPX neg CPY neg)(!CPX CPY)}
}
\expandafter\psrline\points
\end{pspicture}
\end{document}


It produces two outputs as follows.

## Explanation

When I move the definition of Angles from

xdef\points{\points(!1 Angles 1 \i\space 1 sub sqrt atan add dup /Angles ED PtoC %
dup CPY add /CPY ED exch dup CPX add /CPX ED exch)(!CPX neg CPY neg)(!CPX CPY)}


to

\pstVerb{Angles 1 \i\space 1 sub sqrt atan add /Angles exch def}


why does the output become incorrect?

-

Fundamentally PostScript doesn't translate directly to TeX. Only \space and \i are properly identified and expanded.

When you include the \pstVerb inside the \multido loop, you are storing an updated version of Angles using PostScript. However, the construction of \points does not take this altered version of Angles into consideration, since it's not expanded in the usual TeX way. As such, the call

\expandafter\psrline\points


just uses the latest version of Angles when it does \psrline on the expanded \points.

-
+1 then is there any solution to overcome this limitation? – kiss my armpit Jan 26 '14 at 3:02
@CodeMocker: If you define \Angles using something like pgfmath or fp. – Werner Jan 26 '14 at 3:04
See my answer, I just got it by accident. – kiss my armpit Jan 26 '14 at 4:49

I got the solution as follows.

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5)
\psset{linecolor=red}
\def\points{(0,0)(1,0)}%
\pstVerb
{
/Angles 0 def
/CPx 1 def
/CPy 0 def
/updateCP {2 copy CPy add /CPy ED CPx add /CPx ED} bind def
/updateA  {1 sub sqrt 1 exch atan Angles add /Angles ED} bind def
}
\multido{\i=1+1}{15}
{
\xdef\points{\points(!1 \i\space updateA Angles PtoC updateCP)(!CPx neg CPy neg)(!CPx CPy)}
}
\expandafter\psrline\points
\end{pspicture}
\end{document}

-