Chained Transformation Matrices not producing predicted result

I have a problem for a few days and I can't solve it =[[ I have a composite object of 4 parts and I'm trying to do the translation and rotation operations on it. Each part of the object has a rotation and translation matrix (so I have 4 different rotations and translations).

The steps are:

1. Calculates the transpose of the rotation matrix;
2. Place all the objects in the origin (0,0,0);
3. Define "Origin to Geometry" for all objects;
4. Conversion of the transposed rotation matrix to Euler Angles;
5. Modify the position and rotation of objects with their translations and rotations;

Here is a part of my code:

for i in range (1, 5):
print ("done " + str(i))
bpy.context.scene.objects.active = bpy.data.objects["obj"+str(i)]
obj = bpy.context.scene.objects.active

with open('info/info_' + a + '_00' + str(i-1) + '.txt', newline='') as inputfile:

r1 = results
r2 = results
r3 = results
t = results

r1 = [num.strip().split(" ") for num in r1]
r2 = [num.strip().split(" ") for num in r2]
r3 = [num.strip().split(" ") for num in r3]
t = [num.strip().split(" ") for num in t]

#with transposed matrix
a11 = float(r1)
a12 = float(r2)
a13 = float(r3)
a21 = float(r1)
a22 = float(r2)
a23 = float(r3)
a31 = float(r1)
a32 = float(r2)
a33 = float(r3)
t1 = float(t) # value of x
t2 = float(t) # value of y
t3 = float(t) # value of z

#http://nghiaho.com/?page_id=846
rot_x = atan2(a32,a33) # result in rad
rot_y = atan2(-a31,sqrt(pow(a32,2)+pow(a33,2)))
rot_z = atan2(a21,a11) # to degrees -> degrees(rot_z)

bpy.data.objects["obj" + str(i)].location = [0, 0, 0]
bpy.data.objects["obj" + str(i)].rotation_euler = [0, 0, 0]
bpy.data.objects["obj" + str(i)].rotation_euler = [-rot_x, rot_z, -rot_y]
bpy.data.objects["obj" + str(i)].location = [t1, -t3, t2]

PS: I change the sequence of rotation angles because blenders coordinate system is different

The result is is below. The strange is that the object are disconnected, which can not happen. Does anyone have any suggestions? I also have attached the camera image that I have and that I wish I know that the difference is small but it can not continue my work with this.

information about the matrix

Blender file

Original file

Thanks a lot!

• Does anyone know another method to perform the rotation / translation of an object in blender? – Daniel Caye Apr 29 '15 at 21:35
• are object center, scale as the originals, are you sure the calculation is precise and should output the desired result – Chebhou Apr 29 '15 at 22:43
• Yes I'm sure. I've already performed the operation with another software and the result is equal to the "expected" – Daniel Caye Apr 29 '15 at 22:59
• here is a page about using matrix for transformation but i think you will get the same result, they seems to be shifted ti the right a little that's why i think the origin is off the center – Chebhou Apr 29 '15 at 23:12
• you just find the transform matrix and assign it to obj.matrix_world , BTW are there any parenting relations between this objects (their transformation will be relative to the parent ) – Chebhou Apr 29 '15 at 23:17