OpenGL を使用して、Python で体心立方結晶構造をシミュレートしたいと考えています。next_nodes
ノードが境界を満たしている場合は print を取得し、それ以外の場合は再帰的に返される次のノードを探すコードを作成しました。
しかし、コードには無限に実行されるという問題があります。誰でもこの問題を解決するのを手伝ってくれますか? 以下に関連するコードを投稿します (すべての OpenGL 呼び出しが削除されています)。
def get_node(x,y,z,side):
return [x+side,y,z],[x,y+side,z],[x,y,z+side],[x-side,y,z],[x,y-side,z],[x,y,z-side]
def goto_next_nodes(x,y,z,cube_side,next_nodes,boundary_x,boundary_y,boundary_z):
for node in next_nodes:
if 0<=node[0]<=boundary_x and 0<=node[1]<=boundary_y and 0<=node[2]<=boundary_z:
print node
x,y,z=node[0],node[1],node[2]
next_nodes=get_node(x,y,z,cube_side)
goto_next_nodes(x,y,z,cube_side,next_nodes,boundary_x,boundary_y,boundary_z)
else:
return
def display_fcc(cube_side,boundary_x,boundary_y,boundary_z):
x=y=z=0
next_nodes=get_node(x,y,z,cube_side)
goto_next_nodes(x,y,z,cube_side,next_nodes,boundary_x,boundary_y,boundary_z)
display_fcc(5,10,10,10)
display_fcc
再帰は関数で始まりgoto_next_node
、再帰関数です。