3
$\begingroup$

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:


        results = list(csv.reader(inputfile))

        r1 = results[4]
        r2 = results[5]
        r3 = results[6]
        t = results[8]

        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[0][0]) 
        a12 = float(r2[0][0])
        a13 = float(r3[0][0])
        a21 = float(r1[0][1])   
        a22 = float(r2[0][2])   
        a23 = float(r3[0][3])
        a31 = float(r1[0][4])
        a32 = float(r2[0][5])
        a33 = float(r3[0][6])
        t1 = float(t[0][0]) # value of x
        t2 = float(t[0][7]) # value of y
        t3 = float(t[0][8]) # 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?

enter image description here

I also have attached the camera image that I have and that I wish

enter image description here

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!

$\endgroup$
  • $\begingroup$ Does anyone know another method to perform the rotation / translation of an object in blender? $\endgroup$ – Daniel Caye Apr 29 '15 at 21:35
  • 1
    $\begingroup$ are object center, scale as the originals, are you sure the calculation is precise and should output the desired result $\endgroup$ – Chebhou Apr 29 '15 at 22:43
  • $\begingroup$ Yes I'm sure. I've already performed the operation with another software and the result is equal to the "expected" $\endgroup$ – Daniel Caye Apr 29 '15 at 22:59
  • $\begingroup$ 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 $\endgroup$ – Chebhou Apr 29 '15 at 23:12
  • $\begingroup$ 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 ) $\endgroup$ – Chebhou Apr 29 '15 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.