I'm taking a computer graphics course. In one assignment I had to check if a matrix transformation maps points to another set of points
I thought that the best way to learn how this was to use Blender's Python API and try doing this.
These are my set of points
t0 = (−1, −1, −1) t1 = (1, 1, −1) t2 = (−1, 1, 1) t3 = (1, −1, 1)
The set of points I want to get mapped to are
u0 = (2, 2, −1) u1 = (2, 2, 3) u2 = (0, 0, 1) u3 = (4, 0, 1)
and the transformation:
Rotation about the z-axis by 45°, then scaling with sx =√2, sy =√2, sz = 1, then translation by (2, 1, −1), and then rotation about the x-axis by 90 degree.
I created the two objects for the two set of objects. And I want to move the object t (with vertices t0,t1 ...) to the object u (with vertices u0, u1 ...)
#rotation around Z axis rot_mat = Matrix.Rotation(radians(90), 4, 'Z') # decompose world_matrix's components orig_loc, orig_rot, orig_scale = obj.matrix_world.decompose() #create the translation vector translation = mathutils.Vector((2,1,-1)) new_loc = orig_loc + translation orig_loc_mat = Matrix.Translation(new_loc) orig_rot_mat = orig_rot.to_matrix().to_4x4() orig_scale_mat = Matrix.Scale(orig_scale,4,(sqrt(2),0,0)) * Matrix.Scale(orig_scale,4,(0,1,0)) * Matrix.Scale(orig_scale,4(0,0,sqrt(2))) obj.matrix_world = orig_loc_mat * rot_mat * orig_rot_mat * orig_scale_mat
This is not working, the object gets mapped to a wrong position. The blue object is the object from t coordinates, the red from the u coordinates, the green one should be overlapping the red one.