# How to draw a line from the origin to the last point of \psrline?

Consider the following code to draw the Theodorus' spiral.

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

\begin{document}

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

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


## Explanation

The first approach with psStartPoint and \psVector,

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


produces

and the second approach with \psrline,

\begin{pspicture}[showgrid](-5,-5)(5,5)
\psset{linecolor=red}
\def\points{(0,0)(1,0)}%
\pstVerb{/Angles 0 def}
\multido{\i=1+1}{15}
{
\xdef\points{\points(!1 Angles 1 \i\space 1 sub sqrt atan add dup /Angles exch def PtoC)}
}
\expandafter\psrline\points
\end{pspicture}


produces incomplete output as follows.

## Question

How can I draw a line from the origin to the last point of \psrline invoked for each iteration?

I have tried the following but (!cp.X cp.Y) does not exist.

  \begin{pspicture}[showgrid](-5,-5)(5,5)
\psset{linecolor=red}
\def\points{(0,0)(1,0)}%
\pstVerb{/Angles 0 def}
\multido{\i=1+1}{15}
{
\xdef\points{\points(!1 Angles 1 \i\space 1 sub sqrt atan add dup /Angles exch def PtoC)}
\expandafter\psrline\points
\psline(! cp.X cp.Y)
}
\end{pspicture}

-
Do you know this topic tex.stackexchange.com/q/155087/14757 ? – Sigur Jan 22 '14 at 14:33
@Sigur: I am exploring many possible ways to solve that problem. :-) – kiss my armpit Jan 22 '14 at 14:36

\psrline takes a list of relative pen movements, not the absolute coordinates of the added vertices.

But you need to know their absolute coordinates in order to be able to draw lines back to the origin.

Thus, you need to keep track of the current pen position. This is done in the code below. Unfortunately the line segments to the origin are drawn twice, because pure 'movetos' cannot be inserted.

\documentclass{article}
\SpecialCoor

\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}
\multido{\i=1+1}{15}
{
\xdef\points{\points(!1 Angles 1 \i\space 1 sub sqrt atan add dup /Angles exch def PtoC %
dup CPY add /CPY exch def exch dup CPX add /CPX exch def exch)(!CPX neg CPY neg)(!CPX CPY)}
}
\expandafter\psrline\points
\end{pspicture}
\end{document}

-