Python transformation matrix in 3D

Hi guys,

I’m very new in Blender and have a question to you…

											I want ann aggregated transformation matrix for transformation in 3D containing (in this order)
  •   					a translation in x direction of 20
    
  •   					a rotation around the z-axis (up-Axis) of PI/2
    
  •   					an uniform scale of 10
    
    
      			
    
      			Then I want to apply the aggregated transformation matrix to the local point P=[px=100, py=100, pz=0] 
    

Till now, I have the following code:

tmatrix=Matrix()
print(trmatrix) :
<Matrix 4x4 (1.0000, 0.0000, 0.0000, 0.0000)
(0.0000, 1.0000, 0.0000, 0.0000)
(0.0000, 0.0000, 1.0000, 0.0000)
(0.0000, 0.0000, 0.0000, 1.0000)>
tmatrix.translation = (20,0,0)
print(trmatrix) :
<Matrix 4x4 (1.0000, 0.0000, 0.0000, 20.0000)
(0.0000, 1.0000, 0.0000, 0.0000)
(0.0000, 0.0000, 1.0000, 0.0000)
(0.0000, 0.0000, 0.0000, 1.0000)>

So the translation should be ok…

But cant find a solution for the whole problem.

Can u help me?

Thanks alot !

Blender_rulz :wink:

One way is to simply compose a translation matrix with a rotation matrix by multiplying them together.


from mathutils import Vector, Matrix
import math


translation = Matrix.Translation( Vector( (20, 0, 0) ) )
rotation = Matrix.Rotation( math.pi/2, 4, "Z")


final = rotation * translation * 10


print(final)

One thing is not fully clear is the order that you want to do these operations and that impacts if you do “translation * rotation” or “rotation * translation”.

When you transform your point the math formula evaluates from right to left. That is:
finalPoint = TransformMatrix * point

If you transform matrix is this:
TransformMatrix = translate * rotate

Then your point will do this:
finalPoint = translate * (rotate * point)

In other words “translate * rotate” with actually “rotate then translate” the point.

Thank you so much !!! It’s working great and your description is so nice, bro ! :smiley:

Have a nice day :slight_smile: