I need to rotate the matrix_world of an object through a quaternion q without changing its actual rotation (i.e. rotation in world space). How to do that through a script?

Edit: Let's say if I rotate the matrix_world by the angle specified by quaternion, then naturally the object will also get rotated in the world space. But I want to undo this object rotation and keep matrix_world rotation. Doing this with translation is straightforward. I would just move all the vertices be the negative Vector and shift the location of the object by positive Vector. So I get translated matrix_world but the object remains at the same place in world space. How do I achieve this with rotation?

  • $\begingroup$ I fail to follow. You want to rotate an object without rotating it? Could you clarify? Do you mean you need to change rotation of your object's origin/local space without changing it's mesh in world space? $\endgroup$ Sep 5, 2022 at 11:58
  • $\begingroup$ blender.stackexchange.com/a/42110/60759 - might be useful. $\endgroup$ Sep 5, 2022 at 12:17
  • $\begingroup$ @MartynasŽiemys Thanks for the link. It discusses only translation of origin. I am talking about rotating the matrix_world. Please see the edit. $\endgroup$ Sep 5, 2022 at 14:11

1 Answer 1


Here's what worked for me (supposing you want to align matrix_world of object obj with quaternion q without changing object rotation in world space):

mw = obj.matrix_world
transMat = q.to_matrix().to_4x4()

for v in plane.data.vertices:
    v.co = transMat.inverted() @ mw @ v.co
obj.matrix_world = transMat

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .