Multiply the world matrix by the object-space vector for world space coordinate:
ob = bpy.data.objects['Cube']
v = ob.data.vertices.co
mat = ob.matrix_world
# Multiply matrix by vertex (see also: https://developer.blender.org/T56276)
loc = mat @ v
# Don't do the reverse!
loc = v @ mat # wrong!
`Object.matrix_world is a 4x4 transformation matrix. It contains translation, rotation and scale. A 4x4 matrix can also be used for mirroring and shearing (not covered in my answer).
[a] [b] [c] [d]
[e] [f] [g] [h]
[i] [j] [k] [l]
[m] [n] [o] [p]
The translation is stored in the first 3 rows of the 4th column of the matrix (
You can also use:
# Create new Vector object
# Access the original matrix' translation
# (assignments will change the matrix, thus the object location!)
Rotation and scale are sort of combined. The rotation is stored in
k. The scale is stored in
k. The values in
k of the rotation are taken and multiplied by the scale factor to store both pieces of information.
To get only the rotation, you need to normalize the 3x3 matrix:
To get only the scale, you can use the utility method:
Or manually, normalize the matrix and divide each of the un-normalized by the normalized components (
# you could do this manually like
# vec / sqrt(vec.x**2 + vec.y**2 + vec.z**2) for every matrix column
nmat = mat.normalized()
scale = Vector((mat / nmat, mat / nmat, mat / nmat))
If you need the world coordinates of all vertices, it's more efficient to use the
It will apply the transformation matrix to the mesh, so multiply the world matrix with all vertex coordinates. You may wonder about the change in orientation of a mesh object in viewport if you do the above. It can be fixed by resetting the
matrix_world (otherwise the transformation will be done twice):
ob.matrix_world = Matrix() # identity matrix