0

基本上,我想找出是否有任何点与列表中的任何组合对齐,但我似乎想不出一个好的方法来做到这一点(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 个点。

谢谢 :)

4

0 回答 0