3

Consider the following minimal working example.

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

\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5)
\pscustom[linecolor=green]
{
    \psline(1,0)
    \code{0 /Angle ED}
    \multido{\i=1+1}{15}
    {
        \rlineto(!1 Angle 1 \i\space 1 sub sqrt Atan add dup /Angle ED PtoC)
        \psline(0,0)(!!CP)
    }   
}
\end{pspicture}

\begin{pspicture}[showgrid](-5,-5)(5,5) 
    \psset{linecolor=blue}
    \psline(1,0)    
    \pstVerb{/Angle 0 def}%
    \psStartPoint(1,0)
    \multido{\i=1+1}{15}
    {
        \psVector[arrows=-](!1 Angle 1 \i\space 1 sub sqrt Atan add dup /Angle ED PtoC)
        %\psline(0,0)(!!CP)
    }
\end{pspicture}

\end{document}

Explanation

There are 2 approaches:

\begin{pspicture}[showgrid](-5,-5)(5,5)
\pscustom[linecolor=green]
{
    \psline(1,0)
    \code{0 /Angle ED}
    \multido{\i=1+1}{15}
    {
        \rlineto(!1 Angle 1 \i\space 1 sub sqrt Atan add dup /Angle ED PtoC)
        \psline(0,0)(!!CP)
    }   
}
\end{pspicture}

produces

enter image description here

and

\begin{pspicture}[showgrid](-5,-5)(5,5) 
    \psset{linecolor=blue}
    \psline(1,0)    
    \pstVerb{/Angle 0 def}%
    \psStartPoint(1,0)
    \multido{\i=1+1}{15}
    {
        \psVector[arrows=-](!1 Angle 1 \i\space 1 sub sqrt Atan add dup /Angle ED PtoC)
        %\psline(0,0)(!!CP)
    }
\end{pspicture}

produces

enter image description here

Question

What is wrong in the second method and how to fix it? I still want to use psVector so please don't throw it in your answer.

3
+150

Inside the \psVector macro, the coordinate is evaluate two or three times, which redefines Angle each time with different values. If you want to stick with \psVector, you must move this definition to a separate macro call. Also, \psVector doesn't define a currentpoint, so that CP is undefined. For this you can use the coordinates cp.X and cp.Y, which get defined:

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

\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5) 
    \psset{linecolor=blue}
    \psline(1,0)    
    \pstVerb{/Angle 0 def}%
    \psStartPoint(1,0)
    \multido{\i=1+1}{15}
    {
        \psVector[arrows=-](! 1 Angle 1 \i\space 1 sub sqrt atan add PtoC)
        \pstVerb{Angle 1 \i\space 1 sub sqrt atan add dup /Angle exch def }%
        \psline(0,0)(! cp.X cp.Y)
    }
\end{pspicture}
\end{document}

enter image description here

Simplification

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

\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5) 
    \psset{linecolor=blue}
    \psline(1,0)  
    \pstVerb{/Angle 0 def}
    \psStartPoint(1,0)% <--- why is % needed? 
    \multido{\i=1+1}{15}
    {% <--- why is % needed?
        \pstVerb{Angle 1 \i\space 1 sub sqrt atan add  /Angle exch def }
        \psVector[arrows=-](! 1 Angle PtoC)
        \psline(0,0)(! cp.X cp.Y)
    }
\end{pspicture}
\end{document}
  • why tx@Dict ? – user2478 Jan 22 '14 at 9:18
  • @Herbert For Atan. But I guess using only tx@Dict begin Atan end would be better, as it would keep a single Angle. – Christoph Jan 22 '14 at 9:34
  • atan doesn't need it. It is for ED, but that can be exch def. And by the way atan exists on all PS level. – user2478 Jan 22 '14 at 9:43
  • @Herbert I know, but not Atan, which is what CodeMocker uses. – Christoph Jan 22 '14 at 9:46
  • yes, but nobody really needs Atan it exists only for some historical reason. – user2478 Jan 22 '14 at 9:50

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.