Drawing of PSTricks figure not precise
Consider the following code:
\documentclass{article}
\usepackage{pstricks-add}
\usepackage[locale=DE]{siunitx}
\ExplSyntaxOn
\cs_new_eq:NN \calculate \fp_eval:n
\ExplSyntaxOff
\def\ORb{\calculate{\SideLength/(2*sin(pi/\NoSides))-2.7}}
\def\ORh{\calculate{\SideLength/(2*sin(pi/\NoSides))-1.1}}
\def\area{\calculate{\NoSides*\SideLength^2*cot(pi/\NoSides)/4}}
\makeatletter
\def\LabelLine{\@ifnextchar[\LabelLine@i{\LabelLine@i[0]}}
\def\LabelLine@i[#1](#2)(#3)#4#5{%
\pcline[linestyle=dashed,offset=#4]{|*-|*}(#2)(#3)
\ncput*[nrot=#1]{#5}
}
\makeatother
\def\polygon#1#2{%
\def\NoSides{#1 }
\def\SideLength{#2 }
\psset{unit=0.75mm}
\begin{pspicture}(-\ORb,-\ORh)(\ORb,\ORh)
\edef\dAngle{\the\numexpr360/\NoSides}
\pstVerb{%
/R \SideLength 180 \NoSides div sin 2 mul div def
/Q R \dAngle\space 2 div tx@Dict begin PtoC end pop def
}
\pscircle(0,0){!R}
\multido{\rA=\numexpr\dAngle/2+\dAngle,\iB=0+1}{\NoSides}{%
\pcline[linewidth=2pt](!R \rA\space PtoC)(!R \rA\space \dAngle\space
add PtoC)
\ifnum\iB=0
\LabelLine[:U](!R \rA\space \dAngle\space add PtoC)(!R \rA\space
PtoC)%
{-8pt}{\SI{\SideLength}{\m}}
\LabelLine(!R \rA\space \dAngle\space add PtoC)(!Q dup){8pt}{$x$}
\LabelLine(!R \rA\space PtoC)(!Q dup){-8pt}{$x$}
\fi
}
\psset{linestyle=dotted}
\psframe(!Q neg dup)(!Q dup)
\rput(!Q neg dup) {\psframe(5,5)}
\rput(!Q neg Q 5 sub){\psframe(5,5)}
\rput(!Q 5 sub Q neg){\psframe(5,5)}
\rput(!Q 5 sub dup) {\psframe(5,5)}
\rput(0,0){$A \approx
\SI[round-mode=places,round-precision=0]{\area}{\square\m}$}
\end{pspicture}
}
\begin{document}
\polygon{8}{60}
\end{document}
As can be seen in the picture, the horizontal line segment in the octagon
is not completely horizontal; why and how do I fix it? Furthermore, how do
I get a smooth connection between the line segments?
No comments:
Post a Comment