mathutils.Matrix.py 748 B

1234567891011121314151617181920212223242526272829
  1. import mathutils
  2. import math
  3. # create a location matrix
  4. mat_loc = mathutils.Matrix.Translation((2.0, 3.0, 4.0))
  5. # create an identitiy matrix
  6. mat_sca = mathutils.Matrix.Scale(0.5, 4, (0.0, 0.0, 1.0))
  7. # create a rotation matrix
  8. mat_rot = mathutils.Matrix.Rotation(math.radians(45.0), 4, 'X')
  9. # combine transformations
  10. mat_out = mat_loc @ mat_rot @ mat_sca
  11. print(mat_out)
  12. # extract components back out of the matrix
  13. loc, rot, sca = mat_out.decompose()
  14. print(loc, rot, sca)
  15. # it can also be useful to access components of a matrix directly
  16. mat = mathutils.Matrix()
  17. mat[0][0], mat[1][0], mat[2][0] = 0.0, 1.0, 2.0
  18. mat[0][0:3] = 0.0, 1.0, 2.0
  19. # each item in a matrix is a vector so vector utility functions can be used
  20. mat[0].xyz = 0.0, 1.0, 2.0