좋아, 잘 모르겠지만 아래는 내가 생각하는 파이썬 코드이다. 모서리를 감안할 때 모든면을 일관된 방향으로 배치하려고 시도합니다. 주어진 얼굴의 방향은 큐브를 배치하여 해당 면만 볼 수있게하는 경우 정점이 시계 방향 순서로 나열되는 것과 같습니다.
FACE_EDGES = [
[(0, 1), (1, 2), (2, 3), (0, 3)],
[(4, 7), (6, 7), (5, 6), (4, 5)],
[(0, 4), (4, 5), (1, 5), (0, 1)],
[(1, 5), (5, 6), (2, 6), (1, 2)],
[(2, 6), (6, 7), (3, 7), (2, 3)],
[(0, 4), (0, 3), (3, 7), (4, 7)]
]
# gets vertices of a face, but may be "clockwise" or
# "counterclockwise"
def get_vertices_from_edges(edges):
verts = [edges[0][0]]
for i in range(3):
for a, b in edges:
if a == verts[-1] and b not in verts:
verts.append(b)
break
if b == verts[-1] and a not in verts:
verts.append(a)
break
return verts
def get_face_vertices(face_edges):
face_verts = []
for edges in face_edges:
face_verts.append(get_vertices_from_edges(edges))
# orientations of vertices may not be correct yet
orient_order = range(6) # the order in which to fix orientations of faces
if face_verts[0][0] not in face_verts[1]:
# make sure the first two faces touch each other, so that all
# subsequent faces will share an edge with a previously
# oriented face
orient_order[1] = 2
orient_order[2] = 1
oriented_edges = set()
for face_index in orient_order:
verts = face_verts[face_index]
edges = zip(verts, verts[-1:] + verts[:-1])
# make it so that if face A and face B share an edge, they
# orient the shared edge in opposite ways
needs_reverse = False
for a, b in edges:
if (a, b) in oriented_edges:
needs_reverse = True
break
if needs_reverse:
verts.reverse()
edges = zip(verts, verts[-1:] + verts[:-1])
for a, b in edges:
oriented_edges.add((a, b))
return face_verts
print get_face_vertices(FACE_EDGES)
# [[0, 1, 2, 3], [4, 7, 6, 5], [0, 4, 5, 1], [1, 5, 6, 2], [2, 6, 7, 3], [3, 7, 4, 0]]
3D 공간에는 "시계 방향"과 같은 것이 없으며 어느 한면에서 평면도를 볼 수 있습니다. 여러분의 그림에서, 두 경우 모두 큐브의 몸체가 우리가보고있는 사각형 뒤쪽에 있다는 것을 의미합니까? 즉, 모니터의 평면보다 더 멀리 떨어져있는 것입니까? 즉, 큐브 바깥 쪽에서 위아래면을 보았습니까? –
내 그림이 잘못되었을 수 있습니다. 기본적으로 큐브의 어떤 점 (예 : 왼쪽 위)을 선택하고 꼭지점 0으로 설정합니다. 거기에서 위의 순서로 큐브에 레이블을 지정하기 시작합니다. 그것은 그 특정한 점이어야한다는 것이 아니라, 내가 선택한 점 일뿐입니다. – uncoded