2

What makes the green line unable to reach the corresponding vertex of the polygon?

enter image description here

\documentclass[pstricks]{standalone}
\usepackage{pst-node,pst-plot}

\begin{document}
\pstVerb{realtime srand}%
\psLoop{10}{%
\begin{pspicture}[saveNodeCoors](-2,-2)(2,2)
    \curvepnodes[plotpoints=10]{0}{360}{Rand 1 add t PtoC}{P}
    \psnpolygon(0,\numexpr\Pnodecount-1){P}
    \curvepnodes[plotpoints=50]{0}{N-P3.x N-P3.y Pyth}{t N-P3.y N-P3.x atan PtoC}{Q}
    \psnline[linecolor=green](0,\Qnodecount){Q}
\end{pspicture}}
\end{document}

Edit

The problem gone if I buffer the node P3 as follows.

\documentclass[pstricks]{standalone}
\usepackage{pst-node,pst-plot}

\begin{document}
\pstVerb{realtime srand}%
\psLoop{10}{%
\begin{pspicture}[saveNodeCoors](-2,-2)(2,2)
    \curvepnodes[plotpoints=10]{0}{360}{Rand 1 add t PtoC}{P}
    \psnpolygon(0,\numexpr\Pnodecount-1){P}
    \pnode(P3){T}
    \curvepnodes[plotpoints=50]{0}{N-T.x N-T.y Pyth}{t N-T.y N-T.x atan PtoC}{Q}
    \psnline[linecolor=green](0,\Qnodecount){Q}
\end{pspicture}}
\end{document}
  • 2
    My guess is that there are two different random number at work: one when you draw the vertex and one when you draw the green line. That is, Rand gets evaluated twice. – Schrödinger's cat Sep 15 at 19:01
  • @Schrödinger'scat: It is counter intuitive. :-) – Money Oriented Programmer Sep 15 at 19:05
  • At least in TikZ this happens and is a standard pit fall. It is also the reason why declare function={rr=1.5*(1+0.1*rnd);} in this post works. – Schrödinger's cat Sep 15 at 19:07
  • 1
    the saved nodes are global, so you overwrite the P3 with the next run. With \pnode(P3){T} you save the global node P3 into the local one T – user187802 Sep 16 at 7:25
  • @user187802: Thank you. It is a nice feature. :-) – Money Oriented Programmer Sep 16 at 9:03
1
\documentclass[pstricks]{standalone}
\usepackage{pst-node,pst-plot}
\begin{document}
  \pstVerb{realtime srand}
  \psLoop{10}{%
    \begin{pspicture}(-2,-2)(2,2)
       \edef\COOR{}\multido{\iA=0+36,\iB=0+1}{10}{%
         \pnode(!Rand 1 add \iA\space PtoC){P\iB}\xdef\COOR{\COOR(P\iB)}}   
       \expandafter\pspolygon\COOR
       \psline[linecolor=green,arrows=-*](P3)
    \end{pspicture}}
\end{document}

enter image description here

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.