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.

enter image description here

Can we use \curvepnodes and \psnline to get the same result as what the following code produces?

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido,pst-node}
\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5)
\def\points{}%
\multido{\r=0.0+0.1}{90}{\xdef\points{\points(!1 \r\space sqrt 700 mul PtoC)}}
\psset{showpoints,dotstyle=o,dotscale=2}
\rput(-1,0){\expandafter\psrline\points}
\end{pspicture}
\end{document}

enter image description here

Note: The segments have equal length.

share|improve this question

2 Answers 2

up vote 4 down vote accepted
+1000

Here is how you can do that:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido,pst-node,pst-plot}
\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5)
  \curvepnodes[plotpoints=90]{0}{89}{%
    -1 0        % starting point
     0 1 t {% start increment end 
      0.1 mul sqrt 700 mul 1 exch PtoC % the coordinates of the relative vector 
      3 -1 roll add 3 1 roll add exch  % add the coordinates to the intermediate result on the stack
    } for }{P}
  \psnline[showpoints,dotstyle=o,dotscale=2](0,89){P} 
\end{pspicture}
\end{document}

The main difference is, that one needs to use absolute coordinates for all nodes. This is done by iterating inside the Postscript expression of \curvepnodes.

The values of plotpoints, tmin and tmax (the first two parameters to \curvepnodes) are choosen such, that t is integer.

So the Postscript part sums up all relative vectors from 0 to t. The -1 0 gives the starting point.

The result is the same as yours :)

enter image description here

Here is a variant, which saves the intermediate results as /myX and /myY in the tx@NodeDict, which is much more efficient:

\documentclass[pstricks,border=12pt]{standalone}
\usepackage{multido,pst-node,pst-plot}
\begin{document}
\begin{pspicture}[showgrid](-5,-5)(5,5)
  \pstVerb{tx@NodeDict begin /myX -1 def /myY 0 def end }%
  \curvepnodes[plotpoints=90]{0}{89}{%
    myX myY
    t 0.1 mul sqrt 700 mul 1 exch PtoC
    3 -1 roll add 3 1 roll add exch
    2 copy /myY ED /myX ED
  }{P}
  \psnline[showpoints,dotstyle=o,dotscale=2](0,89){P} 
\end{pspicture}
\end{document}
share|improve this answer
    
-1 0 is the starting point, 0 the initial value for the for loop, 1 the increment and t the limit. The cvi converts a value to integer. That was necessary for my first try with repeat, but not needed for for, so I removed it. I added some comments in the Postscript part and some remarks. –  Christoph Nov 13 '13 at 13:19
    
Is there an accessible constant that represents dt (increment in t) where dt=(tmax-tmin)/(plotpoints-1)? Sometimes I need it for other calculation done after invoking \curvepnodes. –  Who is crazy first Nov 13 '13 at 18:36
    
Yes, this is defined as dt. –  Christoph Nov 14 '13 at 8:47
    
Using \curvepnodes seems to be inefficient as for each node the calculation starts from 0, does not it? –  Who is crazy first Nov 24 '13 at 17:17
    
@DonutE.Knot No, only my implementation was inefficient. See my edit for a more efficient way. –  Christoph Nov 25 '13 at 9:43
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\begin{document}

\begin{pspicture}[showgrid](-5,-5)(5,5)
\psset{showpoints,dotstyle=o,dotscale=2}
\psStartPoint[P](0,0)
\multido{\r=0.1+0.1}{90}{\psVector[arrows=-](!1 \r\space sqrt 700 mul PtoC)}
\uput[0](P50){P50}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer
2  
It is nice but not using \curvepnodes so it is just the simplification of my code in the question. –  Who is crazy first Nov 13 '13 at 12:32

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.