Graphics, Figures & TablesPSTricks | Draw regular polygons on top of each other

Information and discussion about graphics, figures & tables in LaTeX documents.
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Draw regular polygons on top of each other

Post by CrazyHorse »

svend_tveskaeg wrote:I see. Thank you (once again) for the explanation.

I would very much appreciate it if your would help me one last time; with drawing a hepragon+tetradecagon. If I have misunderstood that

gcd(#vertices, 360) = 1 ==> no possible "shortcuts" in the code when defining the vertices P_0,...,P_{n-1}

then I do not need any further help in this thread.

P.S. I believe that I now understand the basics of RPN notation. :D (See the attached example (the comments are Danish).)
I learned in my youth the german dialect spoken in the northern part of Germany, the reason why I mostly can understand Danish ... :-)

However, back to the RPN ... :-)
Your code looks good. Only a minor remark:

Code: Select all

    \pnode(!0 0){H1}
    

writing is as

Code: Select all

    \pnode(0, 0){H1}
 

will speed up the TeX run.

Do you want to use this code as a base to draw a heptagon?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Draw regular polygons on top of each other

Post by svend_tveskaeg »

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! :D 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. :shock:

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. :shock:
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 2n-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.)
Attachments
vertices.pdf
Vertices.
(61.88 KiB) Downloaded 379 times
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

PSTricks | Draw regular polygons on top of each other

Post by svend_tveskaeg »

@Herbert: Are we done with this thread?

I am just asking because if we are, I will make it as solved.

Edit:
make --> mark
Last edited by svend_tveskaeg on Thu Oct 04, 2012 6:52 pm, edited 2 times in total.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

PSTricks | Draw regular polygons on top of each other

Post by CrazyHorse »

svend_tveskaeg wrote:@Herbert: Are we done with this thread?

I am just asking because if we are, I will make it as solved.
yes, we can close it ...
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: PSTricks | Draw regular polygons on top of each other

Post by svend_tveskaeg »

Okay.

Thank you very much for helping me.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply