Thank you for the code optimization!
CrazyHorse wrote:I learned in my youth the german dialect spoken in the northern part of Germany, the reason why I mostly can understand Danish ...

Aber doch!

I lived only 30 km from the German border when I was a child so I am almost German.
CrazyHorse wrote:Do you want to use this code as a base to draw a heptagon?
I am not sure exactly what code you are talking about. I would like to use
Code: Select all
\begin{figure}
\centering
% Length a.
\def\valA{1 }
% Length k.
\def\valK{\valA 3 sqrt 2 mul 3 sub mul }
\psset{unit=5,offset=-12pt}
\begin{pspicture}(\valA,\valA)
\pstGeonode[CurveType=polygon,PointName=,PointSymbol=none]
(0,0){P0}
(\valA,0){P1}
(!\valA dup add 30 cos mul 30 PtoC){P2}
(!\valA 4 mul 60 cos mul 60 PtoC){P3}
(!\valA dup add 30 cos mul 90 PtoC){P4}
(\valA;120){P5}
\multido{\iA=0+60,\iP=0+1}{6}{%
\rput{\iA}(P\iP){%
\pnode(!\valA \valK sub % a-k = 2x
2 div % a-k/2 = x
0 % y value
){P\iP:1}
\pnode(!\psGetNodeCenter{P\iP:1} \valA P\iP:1.x sub 0){P\iP:2}
} % end of \rput
} % end of \multido
\pcline{|-|}(P3)(P4) \ncput*{$a$}
\pcline{|-|}(P2)(P2:1) \ncput*{$x$}
\pcline{|-|}(P2:1)(P2:2) \ncput*{$k$}
\pcline{|-|}(P2:2)(P3) \ncput*{$x$}
\psset{linestyle=dashed}
\multido{\iA=0+1,\iB=1+1}{5}{\psline(P\iA:2)(P\iB:1)}
\psline(P5:2)(P0:1)
\end{pspicture}
\end{figure}
as the code base.
The more generalized I can get the code, the better. In general, in an
n-gon,
Code: Select all
\def\valK{\valA pi n div cos 1 pi n div cos add div mul }
(\valK = cos(pi/n)/(1+cos(pi/n))*\valA)
Furthermore, the labels on the sides should be placed at something like
Code: Select all
\pcline{|-|}(P[n/2])(P[n/2+1]) \ncput*{$a$}
\pcline{|-|}(P[n/2-1])(P[n/2-1]:1) \ncput*{$x$}
\pcline{|-|}(P[n/2-1]:1)(P[n/2-1]:2) \ncput*{$k$}
\pcline{|-|}(P[n/2-1]:2)(P[n/2]) \ncput*{$x$}
for even
n and
Code: Select all
\pcline{|-|}(P[(n+1)/2])(P[(n+3)/2]) \ncput*{$a$}
\pcline{|-|}(P[(n-1)/2])(P[(n-1)/2]:1) \ncput*{$x$}
\pcline{|-|}(P[(n-1)/2]:1)(P[(n-1)/2]:2) \ncput*{$k$}
\pcline{|-|}(P[(n-1)/2]:2)(P[(n+1)/2]) \ncput*{$x$}
for odd
n.
The rest of the generalizations should be rather obvious.
I hope it makes sense!
P.S. In my code example with RPN notation, the two lines
Code: Select all
\pnode(!1 \valueA \valueC sub){I1}
\pnode(!1 \valueA){I2}
should be
Code: Select all
\pnode(!\indent 1 mul 3 div \valueA \valueC sub){I1}
\pnode(!\indent 1 mul 3 div \valueA){I2}
Update:
svend_tveskaeg wrote:The rest of the generalizations should be rather obvious.

By ``rather obvious'' I mean that it should be obvious
what I want, not
how to do it.
The `ultimate' code would be something where
\def\valN{<number of vertices> }
is given and then both the regular
n-gon (with the regular 2
n-gon on top) and the labels are printed automatically.
Update 2:
I have computed the coordinates for every vertex in an regular
n-gon. (See the attached note.) I have no idea if it is of any help, but here you go.
Update 3:
The expressions for the vertices in Update 2 can (of course) be written somewhat simpler. (See the attached note.)