如何获得的3维阵列的所有24转? [英] How to get all 24 rotations of a 3-dimensional array?

查看:128
本文介绍了如何获得的3维阵列的所有24转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个3维阵列。把它看成是一块砖。有此砖24可能的旋转(即保持其边缘平行于坐标轴)。如何生成所有相应的3维数组?

I have a 3-dimensional array. Think of it as a brick. There are 24 possible rotations of this brick (that keep its edges parallel to coordinate axes). How do I generate all corresponding 3-dimensional arrays?

推荐答案

一个模(半一对骰子)是很方便的观察的24个不同的方向,并可以建议操作顺序生成它们。你会看到,所有的六个面可以是最上面,而下面的两侧可以旋转到四个不同的基本方向。让我们表示两个操作:打开的和的的,其中的开启的绕从一个基本的z轴的模具下,和的的旋转模具90°离你,所以远离面成为底面和邻近面的顶部。这些操作可以使用旋转矩阵EX pressed中提到的费利佩·洛佩斯的答案,也可以是前pressed简单的功能,给当(X,Y,Z)收益率(-y,X,Z )或(X,Z,-y),分别。

A die (half a pair of dice) is handy for observing the 24 different orientations, and can suggest operation sequences to generate them. You will see that any of six faces can be uppermost, and the sides below can be rotated into four different cardinal directions. Let us denote two operations: "turn" and "roll", where turn rotates the die about the z axis from one cardinal to the next, and roll rotates the die 90° away from you, so the away-face becomes the bottom face and the near face the top. These operations can be expressed using rotation matrices as mentioned in the answer of Felipe Lopes, or can be expressed as simple functions that when given (x,y,z) return (-y,x,z) or (x,z,-y), respectively.

总之,如果你把1模具在近面部,2点右键,并在上面3,你会发现,以下步骤序列产生十二个不同的方向与1,2,或3点之上:RTTTRTTTRTTT。然后该序列RTR暴露6,4,5,其中1,2,3最初是,序列的重复RTTTRTTTRTTT生成12取向用4,5,或6的斑点在上面。所提到的序列是嵌入在以下Python code

Anyhow, if you place the die with 1 on the near face, 2 at right, and 3 on top, you will find that the following sequence of steps generates the twelve different orientations with 1, 2, or 3 spots on top: RTTTRTTTRTTT. Then the sequence RTR exposes 6, 4, 5 where 1, 2, 3 originally were, and a repeat of the sequence RTTTRTTTRTTT generates the twelve orientations with 4, 5, or 6 spots on top. The mentioned sequence is embedded in the following python code.

def roll(v): return (v[0],v[2],-v[1])
def turn(v): return (-v[1],v[0],v[2])
def sequence (v):
    for cycle in range(2):
        for step in range(3):  # Yield RTTT 3 times
            v = roll(v)
            yield(v)           #    Yield R
            for i in range(3): #    Yield TTT
                v = turn(v)
                yield(v)
        v = roll(turn(roll(v)))  # Do RTR

p = sequence(( 1, 1, 1))
q = sequence((-1,-1, 1))
for i in sorted(zip(p,q)):
    print i

有关打印出变换对点的排序列表的理由有二:(i)任何脸部朝向可以通过两个角的位置指定; (ii)其则很容易检查每一对,例如通过管道输出到的uniq的的唯一性。

The rationale for printing out a sorted list of transformed pairs of points is twofold: (i) any face orientation can be specified by the locations of two of its corners; (ii) it then is easy to check for uniqueness of each pair, eg by piping output to uniq.

下面是如何排序的输出开始的:

Here is how the sorted output begins:

((-1, -1, -1), (-1, 1, 1))
((-1, -1, -1), (1, -1, 1))
((-1, -1, -1), (1, 1, -1))
((-1, -1, 1), (-1, 1, -1))
((-1, -1, 1), (1, -1, -1))
((-1, -1, 1), (1, 1, 1))
((-1, 1, -1), (-1, -1, 1))
((-1, 1, -1), (1, -1, -1))
((-1, 1, -1), (1, 1, 1))

这篇关于如何获得的3维阵列的所有24转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆