# 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

• hello could you please show a drawing of what you want? Jan 17, 2021 at 5:36
• @moonboots Yes, I have edited the post and added an photos of what I am referencing. As you can see, the rotations are the same numerically, however the are different if you look at it. I want the rotation to look the same, for the bone that is. Jan 17, 2021 at 19:00
• Am even more confused after latest edit. Could you please add an image showing expected result. re copy rotation constraint shown, is the bone "Shoulder.L" the parent of "Shoulder to Elbow.L" ? Jan 18, 2021 at 11:43

Yes, so, in case anyone is wondering how to stack transformation matrices, the code I posted in the question is mostly correct asides from the last line, instead of * you should put in @ signs, like so:

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))
shoulder_bone.matrix_world = orig_loc_mat @ rot_mat @ orig_rot_mat @ orig_scale_mat

• btw for the scale matrix you can use orig_scale_mat = mathutils.Matrix.Diagonal(orig_scale).to_4x4(). Source: blender.stackexchange.com/a/159540/138679 May 25, 2023 at 20:20

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->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 "real" by selecting the constrainted object and using the "apply visual transform" 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.

• Hi, I've tried adding the bone constraint, and yes it copies rotation, however the same issue arises, where the orientation is all wrong. I've added a picture. Edit: I've changed mix option to 'Before Original' and it apparently worked as intended. Jan 18, 2021 at 11:26
• Do you know maybe how I could perform this through a script? Jan 18, 2021 at 11:29
• @eitroo if Copy Rotation in replace mode, world->world, doesn't give you what you want, then you don't want the world space transform of the targeted object as the world space transform of the constrained object. Before even worrying about scripting, it would make sense to figure out exactly what it is that you do want. Jan 18, 2021 at 16:28