基本的に、リスト内の任意の組み合わせと一致するポイントがあるかどうかを調べたいのですが、これを行う良い方法が思いつかないようです (12 レベルのループは少し混乱するでしょう)。以下のコードは、組み合わせを検索し、どのポイントが含まれているかを判断します。次に、結果の組み合わせを検索して、ラインに 4 つのポイントがあるかどうかを確認します (表示を並べ替えると、最終的には 4x4x4 の立方体になります)。組み合わせはあなたが作ることができるすべての可能な行です)
#bit not in the code, just here so you can see the structure
points=[1,4,1],[4,4,3],[2,4,1],[3,4,1],[4,4,1]
possibleCombinations = []
possibleCombinations.append(['(4, 4, 1)', '(3, 4, 1)', '(2, 4, 1)', '(1, 4, 1)'])
possibleCombinations.append(['(4, 4, 4)', '(3, 4, 3)', '(2, 4, 2)', '(1, 4, 1)'])
possibleCombinations.append(['(1, 1, 3)', '(2, 1, 3)', '(3, 1, 3)', '(4, 1, 3)'])
#finds which combinations contain the point
for i in points:
coordinates = (i[0], i[1], i[2])
for j in range(len(possibleCombinations)):
if any(str(coordinates) in s for s in possibleCombinations[j]):
print possibleCombinations[j]
新しく追加されたポイントを処理し、それらが存在する可能性のある組み合わせを見つけ出し、接続されている他のポイントをテストすることだけを考えましたが、これまでのところ、ポイントがどこにあるか(コーナー/エッジ/サイド)の計算しかできませんでした/真ん中)。
'''
combinations:
each corner has 7
each edge has 4
each side has 3 (with 2 diagonal lines running through)
each middle has 2 (with 20 diagonal lines running through)
'''
#temp coordinate
x = 1
y = 1
z = 1
#calculate location
locationNum = 0
if x == 1 or x == 4:
locationNum += 1
else:
locationNum -= 1
if y == 1 or y == 4:
locationNum += 10
else:
locationNum -= 10
if z == 1 or z == 4:
locationNum += 100
else:
locationNum -= 100
if locationNum == 111:
position = "corner"
elif locationNum == 109 or locationNum == 91 or locationNum == -89:
position = "edge"
elif locationNum == -109 or locationNum == -91 or locationNum == 89:
position = "side"
elif locationNum == -111:
position = "middle"
遅くなりましたが、うまくいかなかった複数の試みを開始しました。すべての位置に対して個別の計算を行うことを考えていましたが、それは可能かもしれませんが、斜めの線がこれを少し複雑にし、線の 4 つの点を確認するという問題がまだあります。
ありがとう :)