我正在学习metapost,我想知道如何生成像多边形数字http://en.wikipedia.org/wiki/Polygonal_number这样的图形,我得到三角形数字但不是六角形。
感谢您的帮助。
答案 0 :(得分:2)
我突然意识到,如果你不关心彼此绘制点和线,那么这个问题就很容易了。以下与罪恶一样丑陋,主要是因为使用fullcircle scaled
来定义点,但它有效:
beginfig(1); pair right, nright; u:=1cm; right:=(u,0); path p,q,dot,seg; dot:=fullcircle scaled (u/2); seg:=(0,0)-- (dot shifted right); for N=1 upto 6: p:=dot; nright:=(N*u,0); for i=1 upto N: p:=seg -- (p shifted right); endfor q:=(0,0); for j=1 upto 6: q:=p -- ((q rotated 60) shifted nright); endfor draw q; endfor endfig
此方法适用于所有 n - 对角数字。