\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}
问题:
您可以看到\pspolygon(A1)(A2)(A3)(A4)(A5)%(A6)%(A7)%(A8)
使用 \mypoly{5}{18} n=5
,LaTeX 打印\pspolygon(A1)(A2)(A3)(A4)(A5)
; \mypoly{4}{45} n=4
,LaTeX 打印\pspolygon(A1)(A2)(A3)(A4)
;...
我能怎么做?
答案1
\multido
如果我理解正确的话,您希望自动包含多边形中的所有顶点。这可以通过在定义顶点的相同位置构建顶点列表来实现。
\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}
当然,你可能会发现这样定义完整的图片更加方便。
\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}
答案2
不需要任何循环。你应该让事情变得简单而不是复杂!只需使用\psRing
和。可以用简单的几何方程\PstPolygon
扩展到任何值。n
\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}