如何计算立方体所有 24 次旋转的四元数?
How to calculate the quaternions of all 24 rotations of a cube?
与前面两个问题(, How to get all 24 rotations of a 3-dimensional array?)类似,我想找到一个物体的所有 90 度旋转。但是,我需要这些旋转的四元数。
import numpy as np
import itertools
from pyquaternion import Quaternion
def rotations():
for x, y, z in itertools.permutations([0, 1, 2]):
for sx, sy, sz in itertools.product([-1, 1], repeat=3):
rotation_matrix = np.zeros((3, 3))
rotation_matrix[0, x] = sx
rotation_matrix[1, y] = sy
rotation_matrix[2, z] = sz
if np.linalg.det(rotation_matrix) == 1:
quat = Quaternion(matrix=rotation_matrix)
yield quat.elements
all_rotations = list(rotations())
print(len(all_rotations))
for x in all_rotations:
print(x)
基于类似问题的this answer by Igor Kołakowski。
与前面两个问题(
import numpy as np
import itertools
from pyquaternion import Quaternion
def rotations():
for x, y, z in itertools.permutations([0, 1, 2]):
for sx, sy, sz in itertools.product([-1, 1], repeat=3):
rotation_matrix = np.zeros((3, 3))
rotation_matrix[0, x] = sx
rotation_matrix[1, y] = sy
rotation_matrix[2, z] = sz
if np.linalg.det(rotation_matrix) == 1:
quat = Quaternion(matrix=rotation_matrix)
yield quat.elements
all_rotations = list(rotations())
print(len(all_rotations))
for x in all_rotations:
print(x)
基于类似问题的this answer by Igor Kołakowski。