# Matrix question

Hi.

Excuse for my little english…

I want use matrix to affect only the rotation.

I’ve a simple cube.
I rotate the cube.

When I process the verts of a part of a mesh,
I want apply at this verts the same rotation of the cube,
but not translation ,origin, and size…only rotation

I’ve notice that if I omit the ‘+M[3][x]’ part,
I don’t have the translation.

How to do this?

Thanks,

``````              Manuel
``````

PS: how I can set the same origin for 2 object ?

-Yes you’re right.M[3][0],M[3][1],and M[3][2] means translation(M[3][3] is =1).If they are zero the object is in the origin.But In the diagonal of the
remained part is included size too.

-You can’t set the origin with the matrix but you have always LocX,LocY and LocZ.

To make one object’s origin = another’s origin try this:

``````from Blender import Object
Obj1=Object.Get("Obj1")
Obj2=Object.Get("Obj2")
Obj2.loc = Obj1.loc
``````

Thx, but I must transform only a subset of vertex.

This is the code, from Eeshlo (Great Eeshlo!):

``````

import Blender
from math import *

return [a[0]+b[0], a[1]+b[1], a[2]+b[2]]

def vecsub(a,b):
return [a[0]-b[0], a[1]-b[1], a[2]-b[2]]

# multiply 3X3 matrix (rotation, scaling) with vector
def mulmatvec3x3(m, v):
r = [0.0, 0.0, 0.0]
r[0] = v[0]*m[0][0] + v[1]*m[1][0] + v[2]*m[2][0]
r[1] = v[0]*m[0][1] + v[1]*m[1][1] + v[2]*m[2][1]
r[2] = v[0]*m[0][2] + v[1]*m[1][2] + v[2]*m[2][2]
return r

# creates full 3D rotation matrix
# rx, ry, rz angles in radians
def makeRotMtx3D(rx, ry, rz):
A, B = sin(rx), cos(rx)
C, D = sin(ry), cos(ry)
E, F = sin(rz), cos(rz)
AC, BC = A*C, B*C
return [[D*F,    D*E, -C],
[AC*F-B*E, AC*E+B*F, A*D],
[BC*F+A*E, BC*E-A*F, B*D]]

# The mesh to be rotated, default Plane
ob = Blender.Object.Get('Plane')
me = ob.data

# The rotation point, an Empty
rotp = Blender.Object.Get('Empty').loc
# translate the rotation point to mesh location
rotp = vecsub(rotp, ob.loc)

# make a rotation matrix,
# as a demo here 10 degrees around Z axis
Rmtx = makeRotMtx3D(0, 0, 10.0*pi/180.0)

# now rotate the points
for v in me.verts:
# subtract rotation point
tv = vecsub(v.co, rotp)
# rotate
nv = mulmatvec3x3(Rmtx, tv)
# add the rotation point back again