【问题标题】:How to calculate the quaternions of all 24 rotations of a cube?如何计算立方体所有 24 次旋转的四元数?
【发布时间】:2022-01-18 12:09:45
【问题描述】:

与前两个问题(How to calculate all 24 rotations of 3d array?How to get all 24 rotations of a 3-dimensional array?)类似,我想找到一个物体的所有 90 度旋转。但是,我需要这些旋转的四元数。

【问题讨论】:

    标签: python rotation quaternions


    【解决方案1】:
    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 的类似问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-01
      • 2013-05-03
      相关资源
      最近更新 更多