How can I apply mesh transformations using the Blender's mathutils 3D transformation matrix to a sphere formed using bpy.ops.mesh.primitive_uv_sphere_add()

I am successfully able to construct a 3D transformtaion matrix using mathutils.Matrix.Rotation matrix and mathutils.Matrix.Translation matrix and apply the transform() operation on a mesh created manually using me = bpy.data.meshes.new() and passing it the vertices and faces/edges using me.from_pydata(verts, edges, faces). However, I would like to use the same transformation matrix to apply the corresponding transformations to a sphere.

Can someone point out a way to do the above; or suggest some workaround for the same?

  • $\begingroup$ It is always a good idea to post a working snippet where someone who could answer the question can start with. $\endgroup$
    – stacker
    Jun 12, 2014 at 11:22

1 Answer 1


This can be achieved by getting the mesh of the object and multiplying the transformation matrix to each vertex. (Possibly there is a convenience function for that).

import bpy
from bpy import context
import mathutils
from mathutils import Vector,Quaternion
import math

obj = bpy.data.objects["Cube"]  # particular object by name
#obj = bpy.context.scene.objects.active # active object

# setup whatever matrix
mx = mathutils.Matrix.Rotation(math.radians(15.0), 4, 'X')

mesh = obj.data
for vert in mesh.vertices:
    vert.co = mx * vert.co

You must log in to answer this question.

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