3
\documentclass[border=10pt,pstricks]{standalone}
\usepackage{xfp,pst-eucl}
\begin{document}
\begin{pspicture}[showgrid,linejoin=1](-2,-2)(2,2)
%%%
\def\mypoly#1#2{% #1: sides, #2: angles
\pnode(0,0){O}
\def\n{#1}
\def\goc{\fpeval{round(360/#1,2)}} %%  https://tex.stackexchange.com/questions/425043/decimal-on-divison
\multido{\iA=1+1}{#1}{\pnode(1;\fpeval{#2+\iA*\goc}){A\iA}}
\pstProjection[PointName=,PointSymbol=none]{A1}{A2}{O}[K]
\pstTriangleOC[fillstyle=solid,fillcolor=red]{A1}{A2}{A3}
\pspolygon(A1)(A2)(A3)(A4)(A5)%(A6)%(A7)%(A8)
\pstCircleOA[fillstyle=solid,fillcolor=white]{O}{K}}
%%%%%
\mypoly{5}{18}
\end{pspicture}
\end{document}

enter image description here

Question:

You can see \pspolygon(A1)(A2)(A3)(A4)(A5)%(A6)%(A7)%(A8)

With \mypoly{5}{18} n=5 , LaTeX print \pspolygon(A1)(A2)(A3)(A4)(A5); \mypoly{4}{45} n=4 , LaTeX print \pspolygon(A1)(A2)(A3)(A4); ...

How can I do?

  • You can use loop of TeX. – Black Mild Oct 31 '19 at 18:29
5

If I understand the question correctly, you want to automatically involve all of the vertices in the polygon. This can be achieved by building up the list of vertices in the same \multido in which you define the vertices.

\documentclass[border=10pt,pstricks]{standalone}
\usepackage{xfp,pst-eucl}
\begin{document}
\begin{pspicture}[showgrid,linejoin=1](-2,-2)(2,2)
%%%
\def\mypoly#1#2{%
\pnode(0,0){O}
\def\n{#1}
\def\goc{\fpeval{round(360/#1,2)}} %%  https://tex.stackexchange.com/questions/425043/decimal-on-divison
\edef\mypoly{}
\multido{\iA=1+1}{#1}{\pnode(1;\fpeval{#2+\iA*\goc}){A\iA}%
\xdef\mypoly{\mypoly(A\iA)}}
\pstProjection[PointName=,PointSymbol=none]{A1}{A2}{O}[K]
\pstTriangleOC[fillstyle=solid,fillcolor=red]{A1}{A2}{A3}
\edef\temp{\noexpand\pspolygon\mypoly}
\temp
\pstCircleOA[fillstyle=solid,fillcolor=white]{O}{K}}
%%%%%
%\mypoly{5}{18}
%\mypoly{6}{18}
\mypoly{7}{18}
\end{pspicture}
\end{document}

enter image description here

Of course, you may find it more convenient to define the full pic like this.

\documentclass{article}
\usepackage{pstricks}
\usepackage{xfp,pst-eucl}
\begin{document}
\def\mypolypic#1#2{%
\begin{pspicture}[showgrid,linejoin=1](-2,-2)(2,2)
%%%
\pnode(0,0){O}
\def\n{#1}
\def\goc{\fpeval{round(360/#1,2)}} %%  https://tex.stackexchange.com/questions/425043/decimal-on-divison
\edef\mypoly{}
\multido{\iA=1+1}{#1}{\pnode(1;\fpeval{#2+\iA*\goc}){A\iA}%
\xdef\mypoly{\mypoly(A\iA)}}
\pstProjection[PointName=,PointSymbol=none]{A1}{A2}{O}[K]
\pstTriangleOC[fillstyle=solid,fillcolor=red]{A1}{A2}{A3}
\edef\temp{\noexpand\pspolygon\mypoly}
\temp
\pstCircleOA[fillstyle=solid,fillcolor=white]{O}{K}
\end{pspicture}}
%%%%%
\multido{\iB=3+1}{8}{\noindent
\mypolypic{\iB}{18}\ifodd\iB\else\\\fi}

\end{document}

enter image description here

1

no need for any loop. You should make things simpel and not complecated! Simply use \psRing and \PstPolygon. Can be extended to any value n with simple geometry equations.

\documentclass[border=10pt,pstricks]{standalone}
\usepackage{xfp,pst-eucl,pst-poly}
\newcommand\myPoly[2][]{{%
  \psRing[fillstyle=solid,fillcolor=red,#1](0,0){\fpeval{cos(1/#2*3.14)}}{1}%
  \PstPolygon[PolyNbSides=#2,PstPicture=false,PolyRotation=\fpeval{90/#2},#1]%  
}}
\begin{document}

\begin{pspicture}[showgrid,linejoin=1](-2,-2)(2,2)
\myPoly[unit=2,PolyRotation=\fpeval{180/8}]{8}
\myPoly[fillcolor=blue!40]{5}
\end{pspicture}

\end{document}

enter image description here

  • Your simplification is differ from my thinking! Really, my code does not use pst-poly package (I have seen it before) and \psRing , both is difficult for junior users as myself. :-), – justonly Oct 31 '19 at 10:04
  • then calculate the inner and outer radius which is simple for a polygon. – user187802 Oct 31 '19 at 10:24

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.