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.

Consider the following code to draw the Theodorus' spiral.

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

\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

enter image description here

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.

enter image description here

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}
share|improve this question
    
Do you know this topic tex.stackexchange.com/q/155087/14757 ? –  Sigur Jan 22 at 14:33
    
@Sigur: I am exploring many possible ways to solve that problem. :-) –  Please don't touch Jan 22 at 14:36

1 Answer 1

up vote 4 down vote accepted
+300

\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}
\usepackage{pstricks-add}
\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}
share|improve this answer

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.