2013-02-17 64 views

回答

2

對於六邊形的環可以定義一個函數是這樣的:

def HexagonRing(x,y,n,r): 
    dc = n*math.sqrt(3) # distance between to neighbouring hexagon centers 
    xc,yc = x,y-r*dC# hexagon center of one before first hexagon (=last hexagon) 
    dx,dy = -dc*math.sqrt(3)/2,dc/2 # direction vector to next hexagon center 
    for i in range(0,6): 
     # draw r hexagons in line 
     for j in range(0,r): 
      xc,yc = xc+dx,yc+dy 
      Hexagon(xc,yc,n) 
     # rotate direction vector by 60° 
     dx,dy = (math.cos(math.pi/3)*dx+math.sin(math.pi/3)*dy, 
       -math.sin(math.pi/3)*dx+math.cos(math.pi/3)*dy) 

那麼可以在其他以後畫一個圈:

Hexagon(0,0,10) 
HexagonRing(0,0,10,1) 
HexagonRing(0,0,10,2) 
HexagonRing(0,0,10,3) 
+0

非常感謝!這非常有幫助。 – user2063057 2013-02-17 23:31:50