这个问题类似于如何改进我的 PSTricks 代码来构建三角形图?。
考虑以下示例。
代码
% pdflatex -shell-escape test.tex
\documentclass{article}
\usepackage{
auto-pst-pdf,
pst-eucl,
pstricks-add
}
\begin{document}
\def\laengde{6}
\def\startX{3}
\def\startY{0}
\pstFPdiv\konstA{\laengde}{2}
\pstFPsub\Bmin{\startX}{\konstA}
\pstFPadd\Bmaks{\startX}{\konstA}
\pstFPadd\Hmin{\startY}{0}
\pstFPdiv\konstB{3 sqrt}{2}
\pstFPmul\Hmaks{\konstB}{\laengde}
\begin{pspicture}(\Bmin,\Hmin)(\Bmaks,\Hmaks)
\cnodeput(\startX,\startY){A}{$1$}
\cnodeput(!\startX\space \laengde\space 6 div sub \startY\space \laengde\space 3 sqrt 2 mul div add){B}{$2$}
\cnodeput(!\startX\space \laengde\space 6 div add \startY\space \laengde\space 3 sqrt 2 mul div add){C}{$3$}
\cnodeput(!\startX\space \laengde\space 3 div sub \startY\space \laengde\space 3 sqrt div add){D}{$4$}
\cnodeput(!\startX\space \startY\space \laengde\space 3 sqrt div add){E}{$5$}
\cnodeput(!\startX\space \laengde\space 3 div add \startY\space \laengde\space 3 sqrt div add){F}{$6$}
\cnodeput(!\startX\space \laengde\space 2 div sub \startY\space \laengde\space 3 sqrt 2 div mul add){G}{$7$}
\cnodeput(!\startX\space \laengde\space 6 div sub \startY\space \laengde\space 3 sqrt 2 div mul add){H}{$8$}
\cnodeput(!\startX\space \laengde\space 6 div add \startY\space \laengde\space 3 sqrt 2 div mul add){I}{$9$}
\cnodeput(!\startX\space \laengde\space 2 div add \startY\space \laengde\space 3 sqrt 2 div mul add){J}{\scriptsize{$10$}}
\psset{
linewidth=1.5pt,
linecolor=red
}
\ncline{A}{B}
\ncline{B}{D}
\ncline{D}{G}
\ncline{G}{H}
\ncline{H}{I}
\ncline{I}{J}
\ncline{J}{F}
\ncline{F}{C}
\ncline{C}{A}
\psset{
linewidth=0.5pt,
linecolor=black,
LabelSep=0.8,
arrows=<->
}
\pstMarkAngle{J}{A}{G}{\SI{60}{\degree}}
\pstMarkAngle{A}{G}{J}{\SI{60}{\degree}}
\pstMarkAngle{G}{J}{A}{\SI{60}{\degree}}
\end{pspicture}
\end{document}
输出
问题
我有想要的输出,但是代码相当混乱;有人能帮我简化一下吗?
答案1
pstricks.tex
需要最新版本\Cnodeput
;可以从以下位置下载http://texnik.dante.de/tex/generic/pstricks/因为 TeX Live 2012 已关闭更新。
\documentclass{article}
\usepackage{auto-pst-pdf,pst-eucl}
\def\CirclePut#1{\pscircle*[linecolor=white]{\Radius}\pscircle{\Radius}\rput(0,0){#1}}
\def\NPcline#1#2#3#4{%
\ncline[linecolor=red,linewidth=1.5pt]{#1}{#2}% the visible one
\pcline[linestyle=none](#1)(#2)% the invisible for correct length
\ncput[npos=0.333]{\CirclePut{#3}}%
\ncput[npos=0.667]{\CirclePut{#4}}}
\def\laengde{6 } \def\Radius{3mm }
\begin{document}
\begin{pspicture}(\laengde,\laengde)
\psset{radius=\Radius}
\Cnodeput(!\laengde 2 div 0){N1}{1}
\Cnodeput(!0 \laengde 3 sqrt mul 2 div){N7}{7}
\Cnodeput(!\laengde dup 3 sqrt mul 2 div){N10}{10}
\NPcline{N1}{N7}{2}{4}
\NPcline{N7}{N10}{8}{9}
\NPcline{N1}{N10}{3}{6}
\pnode(!\laengde dup 2 div exch 3 sqrt mul 6 div 2 mul){N1-10}
\rput(N1-10){\CirclePut{5}}
\psset{linewidth=0.5pt,LabelSep=0.8,arrows=<->}
\pstMarkAngle{N10}{N1}{N7}{$60^\circ$}
\pstMarkAngle{N1}{N7}{N10}{$60^\circ$}
\pstMarkAngle{N7}{N10}{N1}{$60^\circ$}
\end{pspicture}
\end{document}
另一种可能性是将 y 单位设置为0.866
(即大约 sqrt (3)/2),然后我们在两个方向上都有相同的步长,并且可以具有可变的大小:
\documentclass{article}
\usepackage[pdf]{pstricks}% for running pdflatex --shell-escape
\usepackage{pst-eucl}
\newcounter{No}
\def\CirclePut#1#2{\pscircle*[linecolor=white]{#2}\pscircle{#2}\rput(0,0){#1}}
\def\Triangle#1#2{%
\psset{radius=#2,yunit=0.866}\setcounter{No}{0}
\begin{pspicture}(#1,#1)
\pspolygon[linecolor=red,linewidth=1.5pt](0,#1)(#1,#1)(!#1 2 div 0)
\multido{\iRow=0+2,\iStep=1+1}{\numexpr#1/2+1}{%
\multido{\iCol=0+2}{\iStep}{%
\stepcounter{No}%
\pnode(!#1 2 div \iStep\space sub 1 add \iCol\space add \iRow){N\theNo}
\rput(N\theNo){\CirclePut{\theNo}{#2}}%
}}
\psset{linewidth=0.5pt,LabelSep=0.8,arrows=<->}
\edef\UpperLeft{\the\numexpr\theNo-#1/2\relax}
\pstMarkAngle{N\theNo}{N1}{N\UpperLeft}{$60^\circ$}
\pstMarkAngle{N1}{N\UpperLeft}{N\theNo}{$60^\circ$}
\pstMarkAngle{N\UpperLeft}{N\theNo}{N1}{$60^\circ$}
\end{pspicture}}
\begin{document}
\Triangle6{3mm} \hspace{1cm}
\Triangle8{3mm}
\end{document}
答案2
单身的:
\documentclass[pstricks]{standalone}
\usepackage{pst-node,pst-eucl}
\usepackage{multido}
\usepackage[nomessages]{fp}
\FPset\Distance{1}% in cm
\FPset\Radius{.25}% in cm
\psset{MarkAngleRadius=.4,LabelSep=.6,arrows=<->,arcsep=2\pslinewidth,arrowinset=0,arrowscale=0.6,dimen=outer}
\def\Picture#1{%
\FPeval\Right{round((#1-1)*Distance/2+Radius:3)}%
\FPeval\Left{round(-Right:3)}%
\FPeval\Top{round((#1-1)*Distance*root(2,3)/2+Radius:3)}%
\FPeval\Bottom{round(-Radius:3)}%
\begin{pspicture}[showgrid=false](\Left,\Bottom)(\Right,\Top)
\pstVerb{/Distance \Distance\space def /Radius \Radius\space def}%
\pnodes{V}
(!0 \Bottom\space Radius add)
(!\Left\space Radius add \Top\space Radius sub)
(!\Right\space Radius sub \Top\space Radius sub)
\pspolygon[linecolor=red,linewidth=2\pslinewidth](V0)(V1)(V2)
\pstMarkAngle{V0}{V1}{V2}{\tiny$60^\circ$}
\pstMarkAngle{V1}{V2}{V0}{\tiny$60^\circ$}
\pstMarkAngle{V2}{V0}{V1}{\tiny$60^\circ$}
\multido{\iy=0+1}{#1}{%
\multido{\ix=0+1}{\numexpr\iy+1}{%
\pnode(!\iy\space Distance mul 2 div neg \ix\space Distance mul add \iy\space Distance mul 3 sqrt mul 2 div){P}
\FPeval\temp{round(\ix+(\iy+1)*\iy/2+1:0)}%
\pscircle[fillstyle=solid,fillcolor=yellow](P){\Radius}
\rput(P){\temp}}}
\end{pspicture}}
\begin{document}
\Picture{10}
\end{document}
多种的:
\documentclass{article}
\usepackage[a3paper,margin=1cm,landscape]{geometry}
\usepackage{multicol}
\pagestyle{empty}
\usepackage{pst-node,pst-eucl}
\usepackage{multido}
\usepackage[nomessages]{fp}
\FPset\Distance{1}% in cm
\FPset\Radius{.25}% in cm
\psset{MarkAngleRadius=.4,LabelSep=.6,arrows=<->,arcsep=\pslinewidth,arrowinset=0,arrowscale=0.6,dimen=middle}
\def\Picture#1{%
\FPeval\Right{round((#1-1)*Distance/2+Radius:3)}%
\FPeval\Left{round(-Right:3)}%
\FPeval\Top{round((#1-1)*Distance*root(2,3)/2+Radius:3)}%
\FPeval\Bottom{round(-Radius:3)}%
\begin{pspicture}[showgrid=false](\Left,\Bottom)(\Right,\Top)
\pstVerb{/Distance \Distance\space def /Radius \Radius\space def}%
\pnodes{V}
(!0 \Bottom\space Radius add)
(!\Left\space Radius add \Top\space Radius sub)
(!\Right\space Radius sub \Top\space Radius sub)
\pspolygon[linecolor=red](V0)(V1)(V2)
\pstMarkAngle{V0}{V1}{V2}{\tiny$60^\circ$}
\pstMarkAngle{V1}{V2}{V0}{\tiny$60^\circ$}
\pstMarkAngle{V2}{V0}{V1}{\tiny$60^\circ$}
\multido{\iy=0+1}{#1}{%
\multido{\ix=0+1}{\numexpr\iy+1}{%
\pnode(!\iy\space Distance mul 2 div neg \ix\space Distance mul add \iy\space Distance mul 3 sqrt mul 2 div){P}
\FPeval\temp{round(\ix+(\iy+1)*\iy/2+1:0)}%
\pscircle[fillstyle=solid,fillcolor=yellow](P){\Radius}
\rput(P){\temp}}}
\end{pspicture}}
\begin{document}
\begin{multicols}{3}
\begin{enumerate}
\setcounter{enumi}{2}
\multido{\i=3+1}{11}{\item\raisebox{-.5\height}{\Picture{\i}}}
\end{enumerate}
\end{multicols}
\end{document}