PSTricks code cannot compile

First: The title is not good; feel free to change it to something appropriate.

Code

Consider the following MWE:

\documentclass{article}

\usepackage{expl3}

\ExplSyntaxOn
\cs_new_eq:NN
\calc
\fp_eval:n
\ExplSyntaxOff

\begin{document}

\begin{figure}[htbp]
\def\sides{6}
\def\sidelength{6}
\def\RelAngle{\calc{360/\sides}}
\centering
\PstPolygon[
PolyNbSides=\sides,
unit=3
]
%   \multido{\rA=0+\RelAngle,\iA=1+1}{\sides}{%
%     \psRelNode[angle=\rA](A)(B){1}{P\iA}
%   }
\end{pspicture}
\end{figure}

\end{document}


I compile using

pdflatex -shell-escape <filename>.tex


Question

Why can the code not compile if the three lines are not outcommented, and how do I make the code compilable with three lines not outcommented?

• I get a PostScript error /undefinedresult in --atan--, followed by Operand stack: Alpha 0.0 0.0 – egreg Mar 24 '13 at 21:43

as written in the documentation \PstPolygon uses an own pspicture environment. If you have more PSTricks commands then you have to disable this with PstPicture=false. However, I don't know what's the meaning of (A) and (B)?

I suppose you want to define the nodes of the the edges which is easier:

\documentclass{article}

\begin{document}
\def\sides{6}
\edef\RelAngle{\numexpr360/\sides}

\begin{pspicture}(-3,-3)(3,3)
\providecommand{\PstPolygonNode}{\psdot[dotsize=0.15](1;\INode)}
\PstPolygon[PstPicture=false,PolyNbSides=\sides,unit=3]
%\multido{\rA=0+\RelAngle,\iA=1+1}{\sides}{%
%   \psRelNode[angle=\rA](A)(B){1}{P\iA}}
\end{pspicture}

\end{document}


• I am really way too tired (or at least I hope that is the explanation). I simple copied the code from another example and completely forgot about A and B. :( Thank you for the elegant code, though, Herbert. – Svend Tveskæg Mar 24 '13 at 21:50
• by the way: there is also a \psHexagon – user2478 Mar 25 '13 at 7:06
• Thank you! How do I specify the coordiates for the center of a polygon? – Svend Tveskæg Mar 25 '13 at 9:47
• it is always (0,0). However, you can use \rput(x,y){\PstPolygon[..]} – user2478 Mar 25 '13 at 9:49
• Nice! (An idea for the pst-poly package: Give the user the option to specify the coordinates for the center of a regular polygon.) – Svend Tveskæg Mar 25 '13 at 9:51

As PSTricks has not provided us with macros accepting coordinates in (<algebraic expression>|<algebraic expression>) to define nodes, so we can abuse \psparametricplot here as follows.

    \psparametricplot[algebraic,plotpoints=2,showpoints]{0}{0}{\X(t)|\Y(t)}


can be used to plot a point at (\X(0),\Y(0)) where both \X(t) and \Y(t) are algebraic expressions in t.

\documentclass[pstricks,border=12pt]{standalone}
\usepackage[nomessages]{fp}
\usepackage{pst-plot}

\newcommand\const[3][3]{%
\edef\temporary{round(#3}%
\expandafter\FPeval\csname#2\expandafter\endcsname
\expandafter{\temporary:#1)}%
\pstVerb{/#2 \csname#2\endcsname\space def}%
}

\const{Offset}{pi/4}% 45 degrees in radian for the angular diplacement
\const{Sides}{3}% number of sides
\const{SideLength}{3}% assuming in cm
\const{Radius}{SideLength/(2*sin(pi/Sides))}% 3 digits after the decimal point
\const{TwoPi}{2*pi}
\const[0]{PlotPoints}{Sides+1}

\def\Picture{%
\psparametricplot[algebraic,plotpoints=\PlotPoints,showpoints]{0}{\TwoPi}{\X(t)|\Y(t)}
\end{pspicture}}

\begin{document}
\Picture
\end{document}


Animation

\documentclass[pstricks,border=12pt]{standalone}
\usepackage[nomessages]{fp}
\usepackage{pst-plot}

\newcommand\const[3][3]{%
\edef\temporary{round(#3}%
\expandafter\FPeval\csname#2\expandafter\endcsname
\expandafter{\temporary:#1)}%
\pstVerb{/#2 \csname#2\endcsname\space def}%
}

\def\Picture#1{%
\const{Offset}{#1/180*pi}%
\const{Sides}{5}% number of sides
\const{SideLength}{3}% assuming in cm
\const{Radius}{SideLength/(2*sin(pi/Sides))}% 3 digits after the decimal point
\const{TwoPi}{2*pi}
\const[0]{PlotPoints}{Sides+1}