How do I calculate a quaternion when I rotate on an X/Y/Z axis

Viewed 401

The picture below is showing a human bone.

  • Red is the bone/object (humerus bone/the bone on your bicep)
  • Orange is X axis
  • Purple is Y axis
  • Pink is Z axis

3D View of bone

If the current position of the bone is 0.0101834 0.038481 -0.0018027 0.9992058 (same position as the picture above) and I want to rotate the bone on the Z axis (pink), by +60 degrees (so rotating the bone towards us). What will the new quaternion values be (without distorting the object aka keeping the same scale)?

So the bone looks something like this:

Rotated on the Z axis

Same question applies, if I want to rotate on the X and Y axis, what would the quaternion values be for the bone.

Note: Each value in the quaternion is between -1 and 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 Answers
Related