How to create a rotation in local space that is equivalent to the rotation in world space? 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
Transforms, as shown, are local transforms, not world transforms.  So yes, you can very easily have two orientations that have the same numbers, but different orientations.
The easiest way to copy a world-space orientation is to use a copy rotation constraint-- either a bone constraint or an object constraint, depending on what you want constrained-- in world-&gt;world space, obviously.  That way, Blender does the math for you.
Constraints won't show up in the transform channel; they use the transform channels as inputs that they modify.  If you want, you can make a constraint &quot;real&quot; by selecting the constrainted object and using the &quot;apply visual transform&quot; operation (from the ctrl a menu for me, in either object or pose mode depending on the type of constraint.)  After applying visual transform, you can delete the constraint, or leave it if you'd prefer.
If you're interested in the pure math associated with this, I would recommend reading (and understanding) https://en.wikipedia.org/wiki/Rotation_matrix .  https://en.wikipedia.org/wiki/Basis_(linear_algebra) may also be useful.