 # Reading current rotation of a bone

Hello,

Can someone tell me how i can get the current rotation of a bone in local space with constraints (eg. IK) applied?

I need this for a driver(script) to compute the components of the rotation:

• Rotation around local x-axis, z-axis (like a sphere coordinate)
• Rotation around its y-axis.

My main problem is that i don’t know how to read the current visual transformation from a bone to start with. The computation itself should be straight forward.

Thank you for your comment. It reaches me right at the moment where i figured it out. I appended an example file for my current solution. I must wonder that such an option is not available for the driver variables itself. It is relatively easy to do and can react to constraints as well.

### Attachments

driver-rotation-source.blend (71.5 KB)

Care to explain your solution? I’ve been doing math all day and don’t feel like figuring out what all your matrix transforms are doing. If you just want to know how a bone has been ‘moved’ then all that data should be encoded in the “poes bone” matrix. But I guess that is relative to the bone at rest and you want a value relative to the World or Object space? So are you just transforming the “pose” delta back to World space?

No. I wanted the rotational result in the local space of the bone compared to it’s rest position after channels and constraints applied. The problem here is that we have two kind of Bones. The “normal Bones” (Bone struct) and “posed Bones” (PoseBone struct).

The matrix (.matrix_local) from the Bone struct gives you the position/rotation/scale of the bone in armature/object space.
The matrix (.matrix) from the PoseBone struct gives you the position/rotation/scale of the bone in armature/object space after channels and constraints applied.

What i did to get the difference between the bones rest pose and its current pose in local space was the following:

At first i computed the “difference” between the child and the parent in rest pose. (the transform from parent-space to child-space)

Mr = Mrp^-1 * Mrc (rp = rest pose parent, rc = rest pose child)

At second i computed the difference between the child and the parent in transformed pose. (channels + constraints applied)

Mt = Mtp^-1 * Mtc (same schematic)

Now i have two new matrices/transforms. Both contain the “offset” between child and parent, while Mt also contains the movement in local space in which I’m interested. So i compute a third difference to eliminate the “offset” (contains location/rotation/scale difference in rest pose as well as the parents transform):

M = Mp^-1 * Mt

M is now a matrix that describes the transform in local space between the childs rest pose and it’s current pose. The rest should be straight forward as described in Conversion between quaternions and Euler angles.

PS: In my example i used a bone with a damped-track constraint as the source. This should probably be eliminated. That means that i should compute this transform as well, because it gives the results i wanted. xrot would be then the difference between local restpose of the child and this “imaginary” bone. Same would go for zrot. yrot would be instead the rotational difference between both bones. (in the example it would be rotational difference between “child” and “damp”, but signed!)

PPS: The matrix_basis and matrix_channel from PoseBones where useless to me. The first does not respect constraints (but is local). The second is only the animation before constraints are applied.