bone matrix and rotation problem

Hello,
My math is poor.

4x4 Bone Matrix include position, scaling and rotation information.


pose_bone = bpy.data.objects[0].pose.bones[ix]


loc, rot, sca = pose_bone.matrix.decompose()


pose_bone.head
pose_bone.rotation_quaternion

pose_bone.head is equal to loc.
Why rot is not equal to rotation_quaternion?
What is the difference between them?

Thanks,

Because the rotation decompose spits out is likely the values for the various channels of the objections rotation and the quaternion is the quaternion values generated for that rotation with whatever set of euler axis rotation order, I would suspect. The former would be a series of three numbers while the latter will be a series of four.

The PoseBone.rotation_quaternion is relative to the parent bone rotation and to the placement in the armature itself. PoseBone.matrix_basis is the matrix that is relative to the parent bone, if you decompose that then you get the same rotation component as PoseBone.rotation_quaternion.

PoseBone.matrix claims it is the “final 4x4 matrix after constraints and drivers are applied (object space)”. It seems to take a point in ‘bone space’ and convert it to the Armature’s Object Space.

i.e. ‘Bone Space’ is coordinates relative to a single bone. You can most easily see this space by selecting a bone and putting your coordinate system to ‘Normal’. In this space (0,0,0) is at the head of the bone and (0, length, 0) is at the tail of the bone.

PoseBone.matrix * Vector( (0,0,0) ) => The object space coordinate of the head of that bone.
PoseBone.matrix * Vector( (0, boneLength, 0) ) => The object space coordinate of the tail of the bone.

Basically, the PoseBone.matrix ‘rotation’ component is encoding rotations to account for parent bone rotations and the position in the Armature object space.