在X / Y / Z轴上旋转时如何计算四元数

时间:2019-10-12 00:45:10

标签: python python-3.x 3d angle quaternions

下面的图片显示了人类的骨骼。

  • 红色是骨骼/物体(肱骨/二头肌上的骨骼)
  • 橙色是X轴
  • 紫色是Y轴
  • 粉红色是Z轴

3D View of bone

如果骨骼的当前位置是0.0101834 0.038481 -0.0018027 0.9992058(与上图相同的位置),并且我想将骨骼沿Z轴(粉红色)旋转+60度(因此将骨骼朝向我们旋转)。新的四元数值是什么(不会使对象失真,也就是保持相同的比例)?

所以骨头看起来像这样:

Rotated on the Z axis

同样的问题适用,如果我想在X和Y轴上旋转,则四元数对骨骼的值是什么。

注意:四元数中的每个值都在-1和1之间


class Bone():
    def __init__(p3, p2, p1, p0):
        self.p3 = p3
        self.p2 = p2
        self.p1 = p1
        self.p0 = p0

    # Degrees = number between -360 and 360
    #           amount to rotate from current bone position
    def rotate_on_x(self, degrees):
        self.p3 = 
        self.p2 =
        self.p1 =
        self.p0 =

    # Degrees = number between -360 and 360
    #           amount to rotate from current bone position
    def rotate_on_y(self, degrees):
        self.p3 = 
        self.p2 =
        self.p1 =
        self.p0 =

    # Degrees = number between -360 and 360
    #           amount to rotate from current bone position
    def rotate_on_z(self, degrees):
        self.p3 = 
        self.p2 =
        self.p1 =
        self.p0 =

# Below are some values I found online but
# unsure how they even calculated it

# No rotation at all
no_rotation1 = Bone(0, 0, 0, -1)
no_rotation2 = Bone(0, 0, 0, 1)

# 90 degree rotation on X
90_degree_x_rotation1 = Bone(-0.707, 0, 0, -0.707)
90_degree_x_rotation2 = Bone(0.707, 0, 0, 0.707)

# 180 degree rotation on x
180_degree_x_rotation1 = Bone(-1, 0, 0, 0)
180_degree_x_rotation2 = Bone(1, 0, 0, 0)

# 270 degree rotation on x
180_degree_x_rotation1 = Bone(0.707, 0, 0, -0.707)
180_degree_x_rotation2 = Bone(-0.707, 0, 0, 0.707)

# 90 degree rotation on Y
90_degree_y_rotation = Bone(0, -0.707, 0, -0.707)

# 180 degree rotation on Y
180_degree_y_rotation = Bone(0, -1, 0, 0)

# 270 degree rotation on Y
270_degree_y_rotation = Bone(0, 0.707, 0, 0)

# 90 degree rotation on Z
90_degree_z_rotation = Bone(0, 0, -0.707, -0.707)

# 180 degree rotation on z
180_degree_z_rotation = Bone(0, 0, -1, 0)

# 270 degree rotation on Z
270_degree_z_rotation = Bone(0, 0, 0.707, -0.707)

0 个答案:

没有答案