Say I have a quaternion rotation in the world space, and I need an object to rotate according to that rotation, however, that object has its own axis. What sort of operations would I need to perform to get the rotation in that objects space?
Asking because rotations when performing manual rotations with a path curve, and a bone, the bone rotations shows a different quaternion to the path, however I know the path is correct, so I assume it has to do with the bones axis or roll or local space.
Edit. An image.
Edit 2. Tried bone constraint.
Edit 3.
Desired result with bone constraint.

I basically need to get this result in script. I've tried decomposing the matrix of the bone and multiplying an additional rotation matrix, however that didn't work. I'm not sure if I'm on the right track, but here's what I did:
rot_mat = Quaternion([0.8223, -0.0175, 0.4313, -0.3707]).to_matrix().to_4x4()
orig_loc, orig_rot, orig_scale = shoulder_bone.matrix.decompose()
orig_loc_mat = Matrix.Translation(orig_loc)
orig_rot_mat = orig_rot.to_matrix().to_4x4()
orig_scale_mat = Matrix.Scale(orig_scale[0],4,(1,0,0)) * Matrix.Scale(orig_scale[1],4,(0,1,0)) * Matrix.Scale(orig_scale[2],4,(0,0,1))
#Is this what it means to apply rotation before original?
shoulder_bone.matrix_world = orig_loc_mat * rot_mat * orig_rot_mat * orig_scale_mat

